Lolly 1.4.27
Loading...
Searching...
No Matches
hashtree.ipp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : hashtree
4 * DESCRIPTION: A tree class that stores a node's children in a hashmap instead
5 * of a list. Can be used to implement a dictionary that maps
6 * strings to strings efficiently.
7 * COPYRIGHT : (C) 2002 Felix Breuer
8 *******************************************************************************
9 * This software falls under the GNU general public license version 3 or later.
10 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
11 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
12 ******************************************************************************/
13
14#ifndef HASHTREE_C
15#define HASHTREE_C
16#include "hashtree.hpp"
17
18/******************************************************************************
19 * Methods normally provided by
20 * CONCRETE_TEMPLATE_2_CODE(hashtree,class,K,class,V);
21 ******************************************************************************/
22
23template <class K, class V>
25 if (this->rep != NULL) INC_COUNT (this->rep);
26}
27
28template <class K, class V> inline hashtree<K, V>::~hashtree () {
29 if (this->rep != NULL) DEC_COUNT (this->rep);
30}
31
32template <class K, class V>
33inline hashtree<K, V>&
35 if (this->rep != NULL) DEC_COUNT (this->rep);
36 this->rep= x.rep;
37 if (x.rep != NULL) INC_COUNT (x.rep);
38 return *this;
39}
40
41/******************************************************************************
42 * Methods of hashtree_rep<K,V>
43 ******************************************************************************/
44
45template <class K, class V>
46inline bool
48 return children->contains (key);
49}
50
51template <class K, class V>
52void
54 child.realize (); // make sure the child has a rep!
55 children (key)= child;
56}
57
58template <class K, class V>
59void
62 add_child (key, child);
63}
64
65template <class K, class V>
66void
70
71template <class K, class V>
72V
74 return label;
75}
76
77/******************************************************************************
78 * Method to ensure that hashtree is non null
79 ******************************************************************************/
80
81template <class K, class V>
82inline void
84 if (rep == NULL) {
86 INC_COUNT (rep);
87 }
88}
89
90/******************************************************************************
91 * Overloaded operators
92 ******************************************************************************/
93
94template <class K, class V>
97 // always make sure there is a rep!
98 realize ();
99 return rep;
100}
101
102template <class K, class V>
103inline hashtree<K, V>
105 if (*this->contains (key)) return *this->children (key);
106 else TM_FAILED ("read-access to non-existent node requested");
107}
108
109template <class K, class V>
110inline hashtree<K, V>
112 realize ();
113 if (!(*this)->contains (key)) (*this)->add_new_child (key);
114 return (*this)->children (key);
115}
116
117/******************************************************************************
118 * Functions
119 ******************************************************************************/
120
121template <class K, class V>
122inline bool
124 return ht.rep == NULL;
125}
126
127template <class K, class V>
128inline int
130 return N (ht->children);
131}
132
133#endif // HASHTREE_C
#define TM_FAILED(msg)
Macro used to throw an exception with a specified error message.
Definition basic.hpp:93
#define DEC_COUNT(R)
Macro used to decrement the reference count for a structure object and delete it if the count reaches...
Definition classdef.hpp:84
#define INC_COUNT(R)
Macro used to increment the reference count for a structure object.
Definition classdef.hpp:74
bool contains(K key)
Definition hashtree.ipp:47
void add_child(K key, hashtree< K, V > &child)
Definition hashtree.ipp:53
void set_label(V val)
Definition hashtree.ipp:67
void add_new_child(K key)
Definition hashtree.ipp:60
void realize()
Definition hashtree.ipp:83
hashtree< K, V > & operator=(hashtree< K, V > x)
Definition hashtree.ipp:34
hashtree_rep< K, V > * operator->(void)
Definition hashtree.ipp:96
hashtree< K, V > operator[](K key)
Definition hashtree.ipp:104
hashtree< K, V > operator()(K key)
Definition hashtree.ipp:111
friend bool is_nil(hashtree< K, V > ht)
Definition hashtree.ipp:123
The list class represents a linked list.
Definition list.hpp:48
list(T item)
Construct a new list object with a single item.
Definition list.hpp:137
int N(hashtree< K, V > ht)
Definition hashtree.ipp:129
bool contains(list< T > l, T what)
Check if a list contains a specific item.
Definition list.ipp:222
base class of resources
Definition resource.hpp:23