HashSet - SashaOrlova/project GitHub Wiki

------Build instructions-------

Install libcds using this instruction https://github.com/khizmax/libcds/blob/master/build/cmake/readme.md After you can inclide file HashSet in your code. File "test.cpp" provided unit tests for testing HashSet. For running test do make, but before change path to libcds in makefile.

------Class Description-------

HashSet<GC, K, Traits> - container where you can keep objects with same hash(with collisions, which can appear in case of bad hash function). Inside it contains feldmanhashmap and collisions kept in list, which type you can choose by yourself. When your try to insert new key in HashSet created new list and inserting this list in FeldmanHashMap, for using all hash. But value with this key may exist, and if it happen new key inserted in list of collisions.
Description of template arguments : GC - type of garbage collector to use. K - type of keys. Traits must contains traits for feldmanhashmap, list_type - one of cds::container::LazyList, cds::container::MichaelList, cds::container::IterableList, cxx_list_allocator - allocator used for create new list.

------ Public Member Functions-------

HashSet()
Creates empty set

~HashSet ()
Destructs the set and frees all data

bool insert (const K& key)
Inserts new element (also with same hash). Except situation when this element in HashSet

bool erase (const K& key)
Deletes the item from the set

template<typename Func >
bool erase (const K& key, Func f)
Deletes the item from the set
The Func interface is
struct functor {
void operator()( value_type& item );
};

template<typename Func >
bool find (const K& key, Func f)
Finds an item in set
The Func interface is
struct functor {
void operator()( K& item, K& key );
};

bool contains (const K& key)
Checks whether the set contains element

guarded_ptr get(const K& key)
Finds an item and returns it

bool empty () const
Checks if the set is empty

size_t size () const
Returns item count in the set.

size_t head_size () const
Returns the size of head node.

size_t array_node_size () const
Returns the size of the array node.

void get_level_statistics (std::vector< feldman_hashmap::level_statistics > &stat) const
Collects tree level statistics into stat