|
| 1 | +/** |
| 2 | + * D header file for C++ Hashtable for unordered_map. |
| 3 | + * |
| 4 | + * Copyright: Copyright (c) 2018 D Language Foundation |
| 5 | + * License: Distributed under the |
| 6 | + * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). |
| 7 | + * (See accompanying file LICENSE) |
| 8 | + * Authors: Emmanuel Nyarko |
| 9 | + * |
| 10 | + */ |
| 11 | +module stdcpp.Hashtable; |
| 12 | + |
| 13 | +import stdcpp.allocator; |
| 14 | +import stdcpp.utility : pair; |
| 15 | +import stdcpp.xutility : StdNamespace; |
| 16 | + |
| 17 | +extern(C++, (StdNamespace)): |
| 18 | + |
| 19 | +version (CppRuntime_Gcc) |
| 20 | +{ |
| 21 | + /** |
| 22 | + * structs for hashtable template arguments to get the right mangling |
| 23 | + */ |
| 24 | + struct hash(T) |
| 25 | + { |
| 26 | + } |
| 27 | + |
| 28 | + struct equal_to(T = void) |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + extern(C++, "__detail") struct _Select1st |
| 33 | + { |
| 34 | + } |
| 35 | + |
| 36 | + extern(C++, "__detail") struct _Mod_range_hashing |
| 37 | + { |
| 38 | + } |
| 39 | + |
| 40 | + extern(C++, "__detail") struct _Default_ranged_hash |
| 41 | + { |
| 42 | + } |
| 43 | + |
| 44 | + extern(C++, "__detail") struct _Prime_rehash_policy |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + extern(C++, "__detail") struct _Hashtable_traits(bool _Cache_hash_code, bool _Constant_iterators, bool _Unique_keys) |
| 49 | + { |
| 50 | + import stdcpp.type_traits : bool_constant; |
| 51 | + alias __hash_cached = bool_constant!(_Cache_hash_code); |
| 52 | + } |
| 53 | + |
| 54 | + extern(C++, "__detail") struct _Hashtable_alloc(_NodeAlloc) |
| 55 | + { |
| 56 | + alias __node_base = _Hash_node_base; |
| 57 | + alias __node_base_ptr = __node_base*; |
| 58 | + alias __buckets_ptr = __node_base_ptr*; |
| 59 | + } |
| 60 | + |
| 61 | + extern(C++, "__detail") struct _Hash_node_base |
| 62 | + { |
| 63 | + _Hash_node_base* _M_next; |
| 64 | + } |
| 65 | + |
| 66 | + extern(C++, "__detail") struct _Hash_node(_Value, bool _Cache_hash_code) |
| 67 | + { |
| 68 | + _Hash_node_base __hb; |
| 69 | + } |
| 70 | + |
| 71 | + alias __umap_traits(bool _cache) = _Hashtable_traits!(_cache, false, true); |
| 72 | + |
| 73 | + alias __umap_hashtable(_Key, _Tp, _Hash, _Pred, Alloc, _Tr = __umap_traits!(false)) = _Hashtable!(_Key, pair!(const(_Key), _Tp), Alloc, _Select1st, _Pred, _Hash, |
| 74 | + _Mod_range_hashing, _Default_ranged_hash, _Prime_rehash_policy, _Tr ); |
| 75 | + extern(C++, class) struct _Hashtable(_Key, _Value, _Alloc, _ExtractKey, _Equal, |
| 76 | + _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits) |
| 77 | + { |
| 78 | + alias size_type = size_t; |
| 79 | + alias __traits_type = _Traits; |
| 80 | + alias __hash_cached = __traits_type.__hash_cached; |
| 81 | + alias __node_type = _Hash_node!(_Value, __hash_cached.value); |
| 82 | + alias __node_alloc_type = allocator_traits!(_Alloc).rebind_alloc!(__node_type); |
| 83 | + alias __hashtable_alloc = _Hashtable_alloc!(__node_alloc_type); |
| 84 | + alias __node_base = __hashtable_alloc.__node_base; |
| 85 | + alias __buckets_ptr = __hashtable_alloc.__buckets_ptr; |
| 86 | + alias __node_base_ptr = __hashtable_alloc.__node_base_ptr; |
| 87 | + |
| 88 | + private: |
| 89 | + |
| 90 | + __buckets_ptr _M_buckets; |
| 91 | + size_type _M_bucket_count = 1; |
| 92 | + __node_base _M_before_begin; |
| 93 | + size_type _M_element_count = 0; |
| 94 | + _RehashPolicy _M_rehash_policy; |
| 95 | + __node_base_ptr _M_single_bucket; |
| 96 | + void* _M_void; |
| 97 | + } |
| 98 | +} |
0 commit comments