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

Unified Diff: runtime/bin/hashmap.h

Issue 9186035: Use hash map for event handler file descriptor map (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r3482 Created 8 years, 11 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 | « runtime/bin/eventhandler_macos.cc ('k') | runtime/bin/hashmap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/hashmap.h
diff --git a/runtime/bin/hashmap.h b/runtime/bin/hashmap.h
new file mode 100644
index 0000000000000000000000000000000000000000..b31dae3df6c3bb798fd9c34848979ed8ada96791
--- /dev/null
+++ b/runtime/bin/hashmap.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef BIN_HASHMAP_H_
+#define BIN_HASHMAP_H_
+
+#include "platform/globals.h"
+
+class HashMap {
+ public:
+ typedef bool (*MatchFun) (void* key1, void* key2);
+
+ static bool SamePointerValue(void* key1, void* key2) {
+ return key1 == key2;
+ }
+
+ // initial_capacity is the size of the initial hash map;
+ // it must be a power of 2 (and thus must not be 0).
+ HashMap(MatchFun match, uint32_t initial_capacity);
+
+ ~HashMap();
+
+ // HashMap entries are (key, value, hash) triplets.
+ // Some clients may not need to use the value slot
+ // (e.g. implementers of sets, where the key is the value).
+ struct Entry {
+ void* key;
+ void* value;
+ uint32_t hash; // The full hash value for key.
+ };
+
+ // If an entry with matching key is found, Lookup()
+ // returns that entry. If no matching entry is found,
+ // but insert is set, a new entry is inserted with
+ // corresponding key, key hash, and NULL value.
+ // Otherwise, NULL is returned.
+ Entry* Lookup(void* key, uint32_t hash, bool insert);
+
+ // Removes the entry with matching key.
+ void Remove(void* key, uint32_t hash);
+
+ // Empties the hash map (occupancy() == 0).
+ void Clear();
+
+ // The capacity of the table. The implementation
+ // makes sure that occupancy is at most 80% of
+ // the table capacity.
+ intptr_t capacity() const { return capacity_; }
+
+ // Iteration
+ //
+ // for (Entry* p = map.Start(); p != NULL; p = map.Next(p)) {
+ // ...
+ // }
+ //
+ // If entries are inserted during iteration, the effect of
+ // calling Next() is undefined.
+ Entry* Start() const;
+ Entry* Next(Entry* p) const;
+
+ private:
+ MatchFun match_;
+ Entry* map_;
+ uint32_t capacity_;
+ uint32_t occupancy_;
+
+ Entry* map_end() const { return map_ + capacity_; }
+ Entry* Probe(void* key, uint32_t hash);
+ void Initialize(uint32_t capacity);
+ void Resize();
+
+ friend class IntSet; // From hashmap_test.cc
+};
+
+#endif // BIN_HASHMAP_H_
« no previous file with comments | « runtime/bin/eventhandler_macos.cc ('k') | runtime/bin/hashmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698