OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 26 matching lines...) Expand all Loading... | |
37 // Allocator defines the memory allocator interface | 37 // Allocator defines the memory allocator interface |
38 // used by HashMap and implements a default allocator. | 38 // used by HashMap and implements a default allocator. |
39 class Allocator BASE_EMBEDDED { | 39 class Allocator BASE_EMBEDDED { |
40 public: | 40 public: |
41 virtual ~Allocator() {} | 41 virtual ~Allocator() {} |
42 virtual void* New(size_t size) { return Malloced::New(size); } | 42 virtual void* New(size_t size) { return Malloced::New(size); } |
43 virtual void Delete(void* p) { Malloced::Delete(p); } | 43 virtual void Delete(void* p) { Malloced::Delete(p); } |
44 }; | 44 }; |
45 | 45 |
46 | 46 |
47 class HashMap { | 47 class HashMap { |
fschneider
2012/02/28 16:54:48
I changed HashMap so that it does not have an allo
Philippe
2012/02/29 10:24:45
Done.
| |
48 public: | 48 public: |
49 static Allocator* DefaultAllocator; | |
50 | |
51 typedef bool (*MatchFun) (void* key1, void* key2); | 49 typedef bool (*MatchFun) (void* key1, void* key2); |
52 | 50 |
53 // initial_capacity is the size of the initial hash map; | 51 // initial_capacity is the size of the initial hash map; |
54 // it must be a power of 2 (and thus must not be 0). | 52 // it must be a power of 2 (and thus must not be 0). |
55 explicit HashMap(MatchFun match, | 53 explicit HashMap(MatchFun match, |
56 Allocator* allocator = DefaultAllocator, | 54 Allocator* allocator = NULL, |
57 uint32_t initial_capacity = 8); | 55 uint32_t initial_capacity = 8); |
58 | 56 |
59 ~HashMap(); | 57 ~HashMap(); |
60 | 58 |
61 // HashMap entries are (key, value, hash) triplets. | 59 // HashMap entries are (key, value, hash) triplets. |
62 // Some clients may not need to use the value slot | 60 // Some clients may not need to use the value slot |
63 // (e.g. implementers of sets, where the key is the value). | 61 // (e.g. implementers of sets, where the key is the value). |
64 struct Entry { | 62 struct Entry { |
65 void* key; | 63 void* key; |
66 void* value; | 64 void* value; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 Entry* map_end() const { return map_ + capacity_; } | 107 Entry* map_end() const { return map_ + capacity_; } |
110 Entry* Probe(void* key, uint32_t hash); | 108 Entry* Probe(void* key, uint32_t hash); |
111 void Initialize(uint32_t capacity); | 109 void Initialize(uint32_t capacity); |
112 void Resize(); | 110 void Resize(); |
113 }; | 111 }; |
114 | 112 |
115 | 113 |
116 } } // namespace v8::internal | 114 } } // namespace v8::internal |
117 | 115 |
118 #endif // V8_HASHMAP_H_ | 116 #endif // V8_HASHMAP_H_ |
OLD | NEW |