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

Go to the source code of this file.

Macros

#define HASHSET_CC
 

Functions

template<class T >
static T * search (list< T > l, T x)
 
template<class T >
hashset< T > copy (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 >
bool operator< (hashset< T > h1, hashset< T > h2)
 Less-than comparison operator for hash sets.
 
template<class T >
bool operator== (hashset< T > h1, hashset< T > h2)
 Equality comparison operator for hash sets.
 
template<class T >
tm_ostreamoperator<< (tm_ostream &out, hashset< T > h)
 
template<class T >
hashset< T > & operator<< (hashset< T > &h, T x)
 Insert an item into a hash set.
 

Macro Definition Documentation

◆ HASHSET_CC

#define HASHSET_CC

Definition at line 13 of file hashset.ipp.

Function Documentation

◆ search()

template<class T >
static T * search ( list< T > l,
T x )
static

Definition at line 37 of file hashset.ipp.

37 {
38 while (!is_nil (l)) {
39 if (l->item == x) return &(l->item);
40 l= l->next;
41 }
42 return NULL;
43}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
The list class represents a linked list.
Definition list.hpp:48

◆ 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

◆ 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

◆ 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==()

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<<() [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}

◆ 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}