The Original CHomP Software
|
This is a template for a set of objects of the given type. More...
#include <hashsets.h>
Public Types | |
typedef element | value_type |
The type of elements stored in the set. More... | |
typedef hashkeys | hashing_method |
The type of hashing. More... | |
Public Member Functions | |
hashedset (int_t initialsize=0, int bequiet=1) | |
The default constructor for creating an empty set of objects. More... | |
hashedset (const hashedset< element, hashkeys > &s) | |
The copy constructor. More... | |
hashedset & | operator= (const hashedset< element, hashkeys > &s) |
The assignment operator. More... | |
~hashedset (void) | |
The destructor. More... | |
int_t | getnumber (const element &e) const |
Finds the given element and returns its number. More... | |
bool | checknum (int_t n) const |
Checks if the given number is an index of some element in the set, that is, if the number is non-negative and strictly smaller than the number of elements in the set. More... | |
bool | check (const element &e) const |
Checks if the given element is in the set. More... | |
const element & | operator[] (int_t n) const |
Returns the element with the given number from the set. More... | |
const element & | get (int_t n) const |
Returns the element with the given number from the set. More... | |
const element & | front () const |
Returns the last element in the set. More... | |
const element & | top () const |
Returns the last element in the set. More... | |
int_t | add (const element &e) |
Adds the given element to the set and returns its number. More... | |
int_t | push (const element &e) |
Adds an element to the set (this is an equivalent of 'add'). More... | |
int_t | push_back (const element &e) |
Adds an element to the set (this is an equivalent of 'add'). More... | |
int | remove (const element &e) |
Removes the given element from the set. More... | |
int | removenum (int_t n) |
Returns an element with the given number from the set. More... | |
int_t | pop () |
Removes the last element from the set. More... | |
hashedset< element, hashkeys > & | add (const hashedset< element, hashkeys > &s) |
Adds an entire set of elements to the set. More... | |
hashedset< element, hashkeys > & | remove (const hashedset< element, hashkeys > &s) |
Removes an entire set of elements from the set. More... | |
int_t | size () const |
Returns the number of elements in the set. More... | |
bool | empty () const |
Returns true if the set is empty. Otherwise returns false. More... | |
void | swap (hashedset< element, hashkeys > &other) |
Swaps two hashed sets by swapping their internal data. More... | |
bool | operator== (const hashedset< element, hashkeys > &other) const |
Verifies whether two hashed sets have the same elements. More... | |
void | intersection (const hashedset< element, hashkeys > &s1, const hashedset< element, hashkeys > &s2) |
Computes the intersection of two hashed sets and adds the result to the current set. More... | |
Public Attributes | |
hashstat * | stat |
Hashed set statistics. More... | |
Private Member Functions | |
int_t | hashfind (const element &e, int_t *addpos=NULL) const |
Finds the position in the hashing table at which the number of the given element should be. More... | |
void | rehash (int_t newsize=0) |
Replace the old hashing table with a new one. More... | |
Static Private Member Functions | |
static bool | numberisprime (const int_t &n) |
Verifies whether the given number is prime or not. More... | |
static int_t | rounduptoprime (int_t n) |
Rounds up the given number to a prime number. More... | |
Private Attributes | |
int_t | nelem |
The number of elements stored in the set. More... | |
multitable< element > | tab |
The table of these elements. More... | |
int | hashing |
Is the hashing table in use? More... | |
int_t | hashsize |
The size of the hashing table. More... | |
int_t | hashcleared |
The number of cleared entries in the hashing table. More... | |
multitable< int_t > | hashtable |
The hashing table. More... | |
Static Private Attributes | |
static const int_t | InitHashSize |
The default initial size of a hashing table. More... | |
static const int_t | InitTabSize |
The initial size of a table in a hashed set. More... | |
static const int_t | StartHashingSize |
The minimal number of elements above which hashing table is actually used. More... | |
This is a template for a set of objects of the given type.
Each of the objects should have two functions for generating hashing keys: "int_t hashkey1 (const object &x)" and "int_t hashkey2 (x)". Note: If you remove elements which are not at the end of the set, then the numbers of other elements can change! In the current solution, the last element is put in place of the removed one, but this behavior may be changed in the future versions of this template.
Definition at line 184 of file hashsets.h.
typedef hashkeys chomp::homology::hashedset< element, hashkeys >::hashing_method |
The type of hashing.
Definition at line 191 of file hashsets.h.
typedef element chomp::homology::hashedset< element, hashkeys >::value_type |
The type of elements stored in the set.
Definition at line 188 of file hashsets.h.
|
explicit |
The default constructor for creating an empty set of objects.
If you expect the set to keep a lot of elements, you may want to set the initial size to something large.
Definition at line 355 of file hashsets.h.
References chomp::homology::hashedset< element, hashkeys >::hashsize, chomp::homology::hashedset< element, hashkeys >::rounduptoprime(), and chomp::homology::hashedset< element, hashkeys >::stat.
chomp::homology::hashedset< element, hashkeys >::hashedset | ( | const hashedset< element, hashkeys > & | s | ) |
The copy constructor.
Definition at line 371 of file hashsets.h.
References chomp::homology::hashedset< element, hashkeys >::stat.
chomp::homology::hashedset< element, hashkeys >::~hashedset | ( | void | ) |
The destructor.
Definition at line 403 of file hashsets.h.
References chomp::homology::sout.
int_t chomp::homology::hashedset< element, hashkeys >::add | ( | const element & | e | ) |
Adds the given element to the set and returns its number.
If the element was already in the set, it is not added the second time, only its number is returned.
Definition at line 471 of file hashsets.h.
hashedset< element, hashkeys > & chomp::homology::hashedset< element, hashkeys >::add | ( | const hashedset< element, hashkeys > & | s | ) |
Adds an entire set of elements to the set.
Definition at line 596 of file hashsets.h.
|
inline |
Checks if the given element is in the set.
Returns true if yes, false if no.
Definition at line 439 of file hashsets.h.
|
inline |
Checks if the given number is an index of some element in the set, that is, if the number is non-negative and strictly smaller than the number of elements in the set.
Returns true if yes, false if no.
Definition at line 433 of file hashsets.h.
|
inline |
Returns true if the set is empty. Otherwise returns false.
Definition at line 625 of file hashsets.h.
|
inline |
Returns the last element in the set.
Definition at line 459 of file hashsets.h.
|
inline |
Returns the element with the given number from the set.
Definition at line 445 of file hashsets.h.
int_t chomp::homology::hashedset< element, hashkeys >::getnumber | ( | const element & | e | ) | const |
Finds the given element and returns its number.
Returns -1 if the element is not in the set.
Definition at line 414 of file hashsets.h.
|
private |
Finds the position in the hashing table at which the number of the given element should be.
If there is -1 there, then the number's element should be written there if adding. Saves to 'addposition' the first cleared position in the hashing table if found or sets it to -1 otherwise.
Definition at line 692 of file hashsets.h.
References chomp::homology::hashkey1(), and chomp::homology::hashkey2().
|
inline |
Computes the intersection of two hashed sets and adds the result to the current set.
Definition at line 664 of file hashsets.h.
|
inlinestaticprivate |
Verifies whether the given number is prime or not.
Note: This procedure is quite inefficient for large numbers.
Definition at line 781 of file hashsets.h.
hashedset< element, hashkeys > & chomp::homology::hashedset< element, hashkeys >::operator= | ( | const hashedset< element, hashkeys > & | s | ) |
The assignment operator.
Definition at line 384 of file hashsets.h.
|
inline |
Verifies whether two hashed sets have the same elements.
Uses the standard comparison operator for the elements.
Definition at line 650 of file hashsets.h.
|
inline |
Returns the element with the given number from the set.
Definition at line 453 of file hashsets.h.
|
inline |
Removes the last element from the set.
Throws an exception if the set is empty.
Definition at line 588 of file hashsets.h.
|
inline |
Adds an element to the set (this is an equivalent of 'add').
Definition at line 510 of file hashsets.h.
|
inline |
Adds an element to the set (this is an equivalent of 'add').
Definition at line 516 of file hashsets.h.
|
private |
Replace the old hashing table with a new one.
The desired size may be given, otherwise an optimal size is determined and the table is made larger or smaller.
Definition at line 737 of file hashsets.h.
References chomp::homology::hashedset< element, hashkeys >::rounduptoprime().
int chomp::homology::hashedset< element, hashkeys >::remove | ( | const element & | e | ) |
Removes the given element from the set.
Returns 0 if successful, -1 if the element was not in the set.
Definition at line 522 of file hashsets.h.
hashedset< element, hashkeys > & chomp::homology::hashedset< element, hashkeys >::remove | ( | const hashedset< element, hashkeys > & | s | ) |
Removes an entire set of elements from the set.
Definition at line 605 of file hashsets.h.
|
inline |
Returns an element with the given number from the set.
Returns 0 if successful, -1 if the number is out of range.
Definition at line 573 of file hashsets.h.
|
staticprivate |
Rounds up the given number to a prime number.
Definition at line 798 of file hashsets.h.
Referenced by chomp::homology::hashedset< element, hashkeys >::hashedset(), and chomp::homology::hashedset< element, hashkeys >::rehash().
|
inline |
Returns the number of elements in the set.
Definition at line 631 of file hashsets.h.
|
inline |
Swaps two hashed sets by swapping their internal data.
Definition at line 637 of file hashsets.h.
References chomp::multiwork::swap().
|
inline |
Returns the last element in the set.
Definition at line 465 of file hashsets.h.
|
private |
The number of cleared entries in the hashing table.
Definition at line 314 of file hashsets.h.
|
private |
Is the hashing table in use?
Definition at line 308 of file hashsets.h.
|
private |
The size of the hashing table.
Definition at line 311 of file hashsets.h.
Referenced by chomp::homology::hashedset< element, hashkeys >::hashedset().
|
private |
The hashing table.
Each entry contains the index of the element in the set, or -1 if the entry is free, or -2 if it was cleared.
Definition at line 318 of file hashsets.h.
|
staticprivate |
The default initial size of a hashing table.
Definition at line 289 of file hashsets.h.
|
staticprivate |
The initial size of a table in a hashed set.
Definition at line 292 of file hashsets.h.
|
private |
The number of elements stored in the set.
Definition at line 302 of file hashsets.h.
|
staticprivate |
The minimal number of elements above which hashing table is actually used.
If the number of elements is below this threshold, then a simple array is used and elements are searched for by going through all the elements of the array.
Definition at line 299 of file hashsets.h.
hashstat* chomp::homology::hashedset< element, hashkeys >::stat |
Hashed set statistics.
Allocate this structure to make the set gather usage and effectiveness statistics. By default this pointer is set to 0. It is deallocated in the destructor.
Definition at line 285 of file hashsets.h.
Referenced by chomp::homology::hashedset< element, hashkeys >::hashedset().
|
private |
The table of these elements.
Definition at line 305 of file hashsets.h.