hash_map


An associative container that manages a set of ordered key/value pairs. The pairs are ordered by key, based on a user-supplied hash function. Only one value can be associated with a particular key. You can quickly find this value due to the hash_map 's underlying data structure.

Hash containers are only a proposed addition to the ANSI/ISO Standard Template Library and have not been accepted for inclusion in the final specification. We have included hash containers in Standards<ToolKit> to provide you with the latest STL technology available.

Library

Standards<ToolKit>

Declaration


#include <ospace/osstd/hashmap.h>

template
  <
  class Key,
  class Value,
  class Hash,
  class Equal,
  class Allocator
  >
class hash_map

Interface

Constructor
explicit hash_map( size_t n , const Hash& hash , const Equal& equal , float load_ratio , const Allocator& alloc )
Constructs an empty map, with n (default 203 ) initial table entries, that orders its keys using the hash function (default Hash() ), key comparison function equal (default Equal() ), and allocator alloc (default Allocator() ). The load_ratio value (default 0.75 ) is used to tune the internal hash table.
Constructor
hash_map( const_iterator first , const_iterator last , size_t n , const Hash& hash , const Equal& equal , float load_ratio , const Allocator& alloc )
Constructs a map that contains copies of the key/value pairs in the range
[ first , last ) .
Constructor
hash_map( const hash_map< Key, Value, Hash, Equal, Allocator >& other )
Constructs a copy of other .
Destructor
~hash_map()
Destroys the map and erases all of its key/value pairs.
=
hash_map< Key, Value, Hash, Equal, Allocator >& operator=( const hash_map< Key, Value, Hash, Equal, Allocator >& other )
Replaces the map's contents with other .
[]
Value& operator []( const Key& key )
If no value is associated with key , associates key with a default-constructed value and returns a reference to this new value. Otherwise, returns a reference to the value already associated with key .
begin
iterator begin()
Returns an iterator positioned at map's first key/value pair.
begin
const_iterator begin() const
Returns an iterator positioned at map's first key/value pair.
bucket_count
size_type bucket_count() const
Returns the number of buckets the map contains.
clear
void clear()
Erases all of map's key/value pairs.
count
size_type count( const Key& key ) const
Returns the number of key/value pairs map contains with a key that matches key .
empty
bool empty() const
Returns true if map contains no entries.
end
iterator end()
Returns an iterator positioned immediately after map's last key/value pair.
end
const_iterator end() const
Returns an iterator positioned immediately after map's last key/value pair.
erase
void erase( iterator pos )
Erases the key/value pair at pos .
erase
void erase( iterator first , iterator last )
Erases the key/value pairs in range [ first , last ) .
erase
size_type erase( const Key& key )
Erases all key/value pairs with a key that matches key and returns the number of elements erased.
find
iterator find( const Key& key )
If map contains a key/value pair with a key that matches key , returns an iterator positioned at the matching pair. Otherwise, returns an iterator positioned at end() .
find
const_iterator find( const Key& key ) const
If map contains a key/value pair with a key that matches key , returns a constant iterator positioned at the matching pair. Otherwise, returns a constant iterator positioned at end() .
get_allocator
Allocator get_allocator() const
Returns a copy of the allocator that map is using to manage storage.
hash_funct
Hash hash_funct() const
Returns a copy of the hash function that map is using to order elements.
insert
pair< iterator, bool > insert( const value_type& pair )
If map does not contain a key/value pair with a key that matches that of pair , inserts a copy of pair and returns a pair with a first element that is an iterator positioned at the new key/value pair and a second element that is true . If map already contains a key/value pair with a key that matches that of pair , returns a pair with a first element that is an iterator positioned at the existing key/value pair and a second element that is false .
insert
void insert( const value_type* first , const value_type* last )
Inserts copies of the key/value pairs in the range [ first , last ) .
insert
void insert( const_iterator first , const_iterator last )
Inserts copies of the key/value pairs in the range [ first , last ) .
key_eq
Equal key_eq() const
Returns the comparison object used to compare map's keys.
max_size
size_type max_size() const
Returns the maximum number of key/value pairs that map can contain.
resize
void resize( size_t n )
Resizes the map to have at least n number of hash buckets.
size
size_type size() const
Returns the number of key/value pairs that map contains.
swap
void swap( hash_map< Key, Value, Hash, Equal, Allocator >& other )
Exchanges the contents of map and other .

Non-Member Functions

==
bool operator==( const hash_map< Key, Value, Equal, Allocator >& x , const hash_map< Key, Value, Equal, Allocator >& y ) const
Returns true if x contains the same items in the same order as y .
<
bool operator<( const hash_map< Key, Value, Equal, Allocator >& x , const hash_map< Key, Value, Equal, Allocator >& y ) const
Returns true if x is lexicographically less than y.
swap
void swap( hash_map< Key, Value, Equal, Allocator >& x , hash_map< Key, Value, Equal, Allocator >& y ) const
Exchanges the contents of x and y .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.