hash_set
|
 |
A container that is optimized for
fast associative lookup. Items are matched using the user-supplied Equal
comparator. When an item is inserted into a hash_set
, it is stored in a data structure that allows the item to be found quickly.
Within the data structure, the items are ordered according to a user-defined Hash
function object. Unlike a hash_multiset , a hash_set
cannot contain multiple copies of the same item.
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/hashset.h>
template< class T, class Hash, class Equal, class Allocator >
class hash_set
Interface
Constructor
explicit
hash_set( size_t n ,
const Hash& hash ,
const Equal& equal ,
float load_ratio ,
const Allocator& alloc )
Constructs an empty set,
with n (default 203 )
initial table entries, that orders its elements 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_set(
const_iterator first ,
const_iterator last ,
size_t n ,
const Hash& hash ,
const Equal& equal ,
float load_ratio ,
const Allocator& alloc )
Constructs a set that
contains copies of elements in the range [ first
, last )
.
Constructor
hash_set(
const hash_set< T, Hash, Equal, Allocator >& other
)
Constructs a set that is
a copy of other .
Destructor
~hash_set()
Destroys the set and
erases all of its items.
=
hash_set<
T, Hash, Equal, Allocator >& operator=( const hash_set< T, Hash,
Equal, Allocator >& other )
Replaces the set's
contents with a copy of other 's.
begin
iterator
begin()
Returns an iterator
positioned at the first element in the set.
begin
const_iterator
begin() const
Returns a constant
iterator positioned at the first element in the set.
bucket_count
size_type
bucket_count() const
Returns the number of
hash buckets that this set contains.
clear
void
clear()
Erases all of the set
elements.
count
size_type
count( const T& value )
const
Returns the number of
elements in the set that match value .
empty
bool
empty() const
Returns true
if the set contains no elements.
end
iterator
end()
Returns an iterator
positioned immediately after the last item in the set.
end
const_iterator
end() const
Returns a constant
iterator positioned immediately after the last item in the set.
erase
void
erase( iterator pos )
Erases the element at pos
.
erase
void
erase( iterator first ,
iterator last )
Erases the elements in
range [ first ,
last ) .
erase
size_type
erase( const T& value )
Erases all elements that
match value and returns the number of elements
erased.
find
iterator
find( const T& value )
If the set contains an
element that matches value , returns an iterator
positioned at the matching element. Otherwise, returns an iterator
positioned at end() .
find
const_iterator
find( const T& value )
const
If the set contains an
element that matches value , returns a constant
iterator positioned at the matching element. Otherwise, returns a constant
iterator positioned at end() .
get_allocator
Allocator
get_allocator() const
Returns a copy of the
allocator the set 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 T& value
)
If the set does not
contain an element that matches value , inserts a
copy of value and returns a pair with a first
element that is an iterator positioned at the new element and with a second
element that is true . If the set already
contains an element that matches value , returns a
pair with a first element that is an iterator positioned at the existing
element and with a second element that is false
.
insert
iterator
insert( iterator pos ,
const T& value )
Inserts a copy of value
if the set does not a contain an element that matches value
, using pos as a hint on where to start searching
for the correct place to insert.
insert
void
insert( const T* first ,
const T* last )
Inserts copies of
elements in the range [ first
, last )
.
insert
void
insert( const_iterator first ,
const_iterator last )
Inserts copies of
elements in the range [ first
, last )
.
key_eq
Equal
key_eq() const
Returns the set's key
comparison object.
max_size
size_type
max_size() const
Returns the maximum
number of entries the set can contain.
resize
void
resize( size_type n )
Resizes this set to
contain at least n hash buckets.
size
size_type
size() const
Returns the number of
entries the set contains.
swap
void
swap( hash_set< T, Hash, Equal, Allocator >& other
)
Exchanges the contents of
set and other .
Non-Member Functions
==
bool
operator==( const hash_set< T, Hash, Equal, Allocator >& x
, const hash_set< T, Hash,
Equal, Allocator >& y )
Returns true
if x contains the same items in the same order as y
.
<
bool
operator<( const hash_set< T, Hash, Equal, Allocator >& x
, const hash_set< T, Hash,
Equal, Allocator >& y )
Returns true
if x is lexicographically less than y
.
swap
void
swap( hash_set< T, Hash, Equal, Allocator >& x
, hash_set< T, Hash, Equal,
Allocator >& y )
Exchanges the contents of
x and y .
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.