Lolly 1.4.28
Loading...
Searching...
No Matches
Classes | Functions
hashset.hpp File Reference
#include "list.hpp"
#include "hashset.ipp"
Include dependency graph for hashset.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  hashset_rep< T >
 The hashset_rep class represents an entry in a hash set. More...
 
class  hashset< T >
 The hashset class represents a hash set. More...
 

Functions

template<class T >
int N (hashset< T > h)
 Get the number of entries in a hash set.
 
template<class T >
tm_ostreamoperator<< (tm_ostream &out, hashset< T > h)
 
template<class T >
bool operator<= (hashset< T > h1, hashset< T > h2)
 Less-than-or-equal-to comparison operator for hash sets.
 
template<class T >
hashset< T > copy (hashset< T > h)
 
 CONCRETE_TEMPLATE_CODE (hashset, class, T)
 
template<class T >
bool operator== (hashset< T > h1, hashset< T > h2)
 Equality comparison operator for hash sets.
 
template<class T >
bool operator< (hashset< T > h1, hashset< T > h2)
 Less-than comparison operator for hash sets.
 
template<class T >
hashset< T > & operator<< (hashset< T > &h, T x)
 Insert an item into a hash set.
 

Function Documentation

◆ N()

template<class T >
int N ( hashset< T > h)
inline

Get the number of entries in a hash set.

Template Parameters
TThe type of the data stored in the hash set.
Parameters
hThe hash set to query.
Returns
int The number of entries in the hash set.

Definition at line 95 of file hashset.hpp.

95 {
96 return h->size;
97}

◆ operator<<() [1/2]

template<class T >
tm_ostream & operator<< ( tm_ostream & out,
hashset< T > h )

Definition at line 112 of file hashset.ipp.

113 {
114 int i= 0, j= 0, n= h->n, size= h->size;
115 out << "{ ";
116 for (; i < n; i++) {
117 list<T> l= h->a[i];
118 for (; !is_nil (l); l= l->next, j++) {
119 out << l->item;
120 if (j != size - 1) out << ", ";
121 }
122 }
123 out << " }";
124 return out;
125}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
The list class represents a linked list.
Definition list.hpp:48

◆ operator<=()

template<class T >
bool operator<= ( hashset< T > h1,
hashset< T > h2 )

Less-than-or-equal-to comparison operator for hash sets.

Template Parameters
TThe type of the data stored in the hash sets.
Parameters
h1The first hash set to be compared.
h2The second hash set to be compared.
Returns
true if the first hash set is less than or equal to the second hash set, false otherwise.

Definition at line 87 of file hashset.ipp.

88 {
89 int i= 0, j= 0, n= h1->n;
90 if (N (h1) > N (h2)) return false;
91 for (; i < n; i++) {
92 list<T> l= h1->a[i];
93 for (; !is_nil (l); l= l->next, j++)
94 if (!h2->contains (l->item)) return false;
95 }
96 return true;
97}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170

◆ copy()

template<class T >
hashset< T > copy ( hashset< T > h)

Definition at line 77 of file hashset.ipp.

77 {
78 int i, n= h->n;
79 hashset<T> h2 (n, h->max);
80 h2->size= h->size;
81 for (i= 0; i < n; i++)
82 h2->a[i]= copy (h->a[i]);
83 return h2;
84}
hashset< T > copy(hashset< T > h)
Definition hashset.ipp:77

◆ CONCRETE_TEMPLATE_CODE()

CONCRETE_TEMPLATE_CODE ( hashset ,
class ,
T  )

◆ operator==()

template<class T >
bool operator== ( hashset< T > h1,
hashset< T > h2 )

Equality comparison operator for hash sets.

Template Parameters
TThe type of the data stored in the hash sets.
Parameters
h1The first hash set to be compared.
h2The second hash set to be compared.
Returns
true if the hash sets are equal, false otherwise.

Definition at line 107 of file hashset.ipp.

107 {
108 return (N (h1) == N (h2)) && (h1 <= h2);
109}

◆ operator<()

template<class T >
bool operator< ( hashset< T > h1,
hashset< T > h2 )

Less-than comparison operator for hash sets.

Template Parameters
TThe type of the data stored in the hash sets.
Parameters
h1The first hash set to be compared.
h2The second hash set to be compared.
Returns
true if the first hash set is less than the second hash set, false otherwise.

Definition at line 100 of file hashset.ipp.

101 {
102 return (N (h1) < N (h2)) && (h1 <= h2);
103}

◆ operator<<() [2/2]

template<class T >
hashset< T > & operator<< ( hashset< T > & h,
T x )

Insert an item into a hash set.

Template Parameters
TThe type of the data stored in the hash set *
Parameters
hThe hash set to insert into.
xThe item to insert.
Returns
hashset<T>& A reference to the modified hash set.

Definition at line 112 of file hashset.ipp.

129 {
130 h->insert (x);
131 return h;
132}