[390] | 1 | // Copyright (C) 2015 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[390] | 6 |
|
---|
| 7 | /**
|
---|
[395] | 8 | * @file unordered_map.hh
|
---|
| 9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
| 10 | * @brief unordered_map
|
---|
| 11 | */
|
---|
[390] | 12 |
|
---|
| 13 | #ifndef NV_STL_UNORDERED_MAP_HH
|
---|
| 14 | #define NV_STL_UNORDERED_MAP_HH
|
---|
| 15 |
|
---|
[395] | 16 | #include <nv/common.hh>
|
---|
[390] | 17 | #include <nv/stl/container/hash_table.hh>
|
---|
| 18 | #include <nv/stl/utility/pair.hh>
|
---|
| 19 |
|
---|
| 20 | namespace nv
|
---|
| 21 | {
|
---|
| 22 | template < typename Pair >
|
---|
| 23 | struct use_first
|
---|
| 24 | {
|
---|
| 25 | typedef Pair argument_type;
|
---|
| 26 | typedef typename Pair::first_type result_type;
|
---|
| 27 | const result_type& operator()( const Pair& arg ) const
|
---|
| 28 | {
|
---|
| 29 | return arg.first;
|
---|
| 30 | }
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | template <
|
---|
| 34 | typename Key,
|
---|
| 35 | typename T,
|
---|
| 36 | typename Hash = hash< Key >,
|
---|
| 37 | typename KeyEqual = equal_to< Key >
|
---|
| 38 | // typename Hash = hash<Key>(),
|
---|
| 39 | // typename Predicate = equal_to<Key>,
|
---|
| 40 | >
|
---|
| 41 | class unordered_map
|
---|
| 42 | : public hash_table< hash_table_entry_stl_map< Key, T, size_t, KeyEqual, Hash > >
|
---|
| 43 | {
|
---|
| 44 | public:
|
---|
| 45 | typedef hash_table< hash_table_entry_stl_map< Key, T, size_t, KeyEqual, Hash > > base_type;
|
---|
| 46 | typedef unordered_map< Key, T, Hash, KeyEqual > this_type;
|
---|
| 47 | typedef typename base_type::size_type size_type;
|
---|
| 48 | typedef typename base_type::key_type key_type;
|
---|
| 49 | typedef typename base_type::mapped_type mapped_type;
|
---|
| 50 | typedef typename base_type::value_type value_type;
|
---|
| 51 | typedef typename base_type::node_type node_type;
|
---|
| 52 | typedef typename base_type::insert_return_type insert_return_type;
|
---|
| 53 | typedef typename base_type::iterator iterator;
|
---|
| 54 | typedef Hash hasher;
|
---|
| 55 | typedef KeyEqual key_equal;
|
---|
| 56 |
|
---|
| 57 | unordered_map() : base_type() { }
|
---|
| 58 | explicit unordered_map( size_type bucket_count ) : base_type( bucket_count ) { }
|
---|
| 59 |
|
---|
| 60 | mapped_type& operator[]( const key_type& key )
|
---|
| 61 | {
|
---|
| 62 | return ( *base_type::insert_key( key ).first ).second;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | using base_type::insert;
|
---|
| 66 |
|
---|
| 67 | // STL compatibility only, hint unused
|
---|
| 68 | iterator insert( const_iterator, const value_type& value )
|
---|
| 69 | {
|
---|
| 70 | return base_type::insert( value ).first;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | #endif // NV_STL_UNORDERED_MAP_HH
|
---|
| 78 |
|
---|