Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2035)

Unified Diff: test/cctest/test-dictionary.cc

Issue 23658031: Implement in-place rehashing of HashTable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-dictionary.cc
diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc
index 21c20bd78aaf2b01223baab5af1b7c40f6d9f27f..b9e8b1ec061c94a896663bba07db901463cc46e5 100644
--- a/test/cctest/test-dictionary.cc
+++ b/test/cctest/test-dictionary.cc
@@ -101,6 +101,57 @@ TEST(ObjectHashTable) {
}
+class ObjectHashTableTest: public ObjectHashTable {
+ public:
+ void insert(int entry, int key, int value) {
+ set(EntryToIndex(entry), Smi::FromInt(key));
+ set(EntryToIndex(entry) + 1, Smi::FromInt(value));
+ }
+
+ int lookup(int key) {
+ return Smi::cast(Lookup(Smi::FromInt(key)))->value();
+ }
+
+ int capacity() {
+ return Capacity();
+ }
+};
+
+
+TEST(HashTableRehash) {
+ LocalContext context;
+ Isolate* isolate = Isolate::Current();
+ Factory* factory = isolate->factory();
+ v8::HandleScope scope(context->GetIsolate());
+ // Test almost filled table.
+ {
+ Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
+ ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
+ int capacity = t->capacity();
+ for (int i = 0; i < capacity - 1; i++) {
+ t->insert(i, i * i, i);
+ }
+ t->Rehash(Smi::FromInt(0));
+ for (int i = 0; i < capacity - 1; i++) {
+ CHECK_EQ(i, t->lookup(i * i));
+ }
+ }
+ // Test half-filled table.
+ {
+ Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
+ ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
+ int capacity = t->capacity();
+ for (int i = 0; i < capacity / 2; i++) {
+ t->insert(i, i * i, i);
+ }
+ t->Rehash(Smi::FromInt(0));
+ for (int i = 0; i < capacity / 2; i++) {
+ CHECK_EQ(i, t->lookup(i * i));
+ }
+ }
+}
+
+
#ifdef DEBUG
TEST(ObjectHashSetCausesGC) {
i::FLAG_stress_compaction = false;
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698