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

Go to the source code of this file.

Classes

struct  hashentry< T, U >
 Hash entry template for key-value pairs. More...
 
class  hashmap_rep< T, U >
 
class  hashmap< T, U >
 A simple hashmap class implementation. More...
 

Macros

#define TMPL   template <class T, class U>
 

Functions

template<class T , class U >
int N (hashmap< T, U > h)
 Returns the size of the given hashmap.
 
template<class T , class U >
tm_ostreamoperator<< (tm_ostream &out, hashmap< T, U > h)
 
template<class T , class U >
hashmap< T, U > copy (hashmap< T, U > h)
 
template<class T , class U >
hashmap< T, U > changes (hashmap< T, U > patch, hashmap< T, U > base)
 Creates a new hashmap containing entries that have changed in the 'patch' compared to 'base'.
 
template<class T , class U >
hashmap< T, U > invert (hashmap< T, U > patch, hashmap< T, U > base)
 Creates a new hashmap containing entries that are different in the 'patch' compared to 'base', but with values taken from 'base'.
 
template<class T , class U >
bool operator== (hashmap< T, U > h1, hashmap< T, U > h2)
 
template<class T , class U >
bool operator!= (hashmap< T, U > h1, hashmap< T, U > h2)
 
 CONCRETE_TEMPLATE_2_CODE (hashmap, class, T, class, U)
 

Macro Definition Documentation

◆ TMPL

#define TMPL   template <class T, class U>

Definition at line 216 of file hashmap.hpp.

Function Documentation

◆ N()

template<class T , class U >
int N ( hashmap< T, U > h)
inline

Returns the size of the given hashmap.

Template Parameters
TThe type of the key in the hashmap.
UThe type of the value in the hashmap.
Parameters
hThe hashmap whose size is to be determined.
Returns
The size of the hashmap.

Definition at line 227 of file hashmap.hpp.

227 {
228 return h->size;
229}

◆ operator<<()

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

Definition at line 134 of file hashmap.ipp.

135 {
136 int i= 0, j= 0, n= h->n, size= h->size;
137 out << "{ ";
138 for (; i < n; i++) {
139 list<hashentry<T, U>> l= h->a[i];
140 for (; !is_nil (l); l= l->next, j++) {
141 out << l->item;
142 if (j != size - 1) out << ", ";
143 }
144 }
145 out << " }";
146 return out;
147}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
The list class represents a linked list.
Definition list.hpp:48

◆ copy()

template<class T , class U >
hashmap< T, U > copy ( hashmap< T, U > h)

Definition at line 81 of file hashmap_extra.ipp.

81 {
82 int i, n= h->n;
83 hashmap<T, U> h2 (h->init, n, h->max);
84 h2->size= h->size;
85 for (i= 0; i < n; i++)
86 h2->a[i]= copy_list (h->a[i]);
87 return h2;
88}
list< hashentry< T, U > > copy_list(list< hashentry< T, U > > l)

◆ changes()

template<class T , class U >
hashmap< T, U > changes ( hashmap< T, U > patch,
hashmap< T, U > base )

Creates a new hashmap containing entries that have changed in the 'patch' compared to 'base'.

Template Parameters
TThe type of the key in the hashmap.
UThe type of the value in the hashmap.
Parameters
patchThe hashmap containing updated key-value pairs.
baseThe original hashmap that serves as the reference.
Returns
A new hashmap containing only the entries that have changed from 'base' to 'patch'.

Definition at line 91 of file hashmap_extra.ipp.

91 {
92 int i;
94 for (i= 0; i < patch->n; i++) {
95 list<hashentry<T, U>> l (patch->a[i]);
96 while (!is_nil (l)) {
97 if (l->item.im != base[l->item.key]) h (l->item.key)= l->item.im;
98 l= l->next;
99 }
100 }
101 return h;
102}
static list< T > init
A static list object used for initializing new list objects.
Definition list.hpp:100

◆ invert()

template<class T , class U >
hashmap< T, U > invert ( hashmap< T, U > patch,
hashmap< T, U > base )

Creates a new hashmap containing entries that are different in the 'patch' compared to 'base', but with values taken from 'base'.

Template Parameters
TThe type of the key in the hashmap.
UThe type of the value in the hashmap.
Parameters
patchThe hashmap containing potentially updated key-value pairs.
baseThe original hashmap that serves as the reference.
Returns
A new hashmap containing only the entries that are different in 'patch' but using the values from 'base'.

Definition at line 105 of file hashmap_extra.ipp.

105 {
106 int i;
108 for (i= 0; i < patch->n; i++) {
109 list<hashentry<T, U>> l (patch->a[i]);
110 while (!is_nil (l)) {
111 if (l->item.im != base[l->item.key]) h (l->item.key)= base[l->item.key];
112 l= l->next;
113 }
114 }
115 return h;
116}

◆ operator==()

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

Definition at line 160 of file hashmap.ipp.

160 {
161 if (h1->size != h2->size) return false;
162 int i= 0, n= h1->n;
163 for (; i < n; i++) {
164 list<hashentry<T, U>> l= h1->a[i];
165 for (; !is_nil (l); l= l->next)
166 if (h2[l->item.key] != l->item.im) return false;
167 }
168 return true;
169}

◆ operator!=()

template<class T , class U >
bool operator!= ( hashmap< T, U > h1,
hashmap< T, U > h2 )

Definition at line 172 of file hashmap.ipp.

172 {
173 return !(h1 == h2);
174}

◆ CONCRETE_TEMPLATE_2_CODE()

CONCRETE_TEMPLATE_2_CODE ( hashmap ,
class ,
T ,
class ,
U  )