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

Go to the source code of this file.

Macros

#define HASHMAP_EXTRA_CC
 
#define TMPL   template <class T, class U>
 
#define H   hashentry<T, U>
 

Functions

template<class T , class U >
list< hashentry< T, U > > copy_list (list< hashentry< T, U > > l)
 
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'.
 

Macro Definition Documentation

◆ HASHMAP_EXTRA_CC

#define HASHMAP_EXTRA_CC

Definition at line 13 of file hashmap_extra.ipp.

◆ TMPL

#define TMPL   template <class T, class U>

Definition at line 16 of file hashmap_extra.ipp.

◆ H

#define H   hashentry<T, U>

Definition at line 17 of file hashmap_extra.ipp.

Function Documentation

◆ copy_list()

template<class T , class U >
list< hashentry< T, U > > copy_list ( list< hashentry< T, U > > l)

Definition at line 72 of file hashmap_extra.ipp.

72 {
73 if (is_nil (l)) return l;
74 else
75 return list<hashentry<T, U>> (
76 hashentry<T, U> (l->item.code, l->item.key, l->item.im),
77 copy_list (l->next));
78}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
The list class represents a linked list.
Definition list.hpp:48
list< hashentry< T, U > > copy_list(list< hashentry< T, U > > l)

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

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