4 #include <rudiments/stdio.h> 5 #include <rudiments/private/rudimentsinlines.h> 6 #include <rudiments/private/nodeinlines.h> 8 #define DICTIONARY_TEMPLATE \ 9 template <class keytype, class valuetype> 11 #define DICTIONARY_CLASS \ 12 dictionary<keytype,valuetype> 15 RUDIMENTS_TEMPLATE_INLINE
16 DICTIONARY_CLASS::dictionary() {
17 trackinsertionorder=
true;
21 RUDIMENTS_TEMPLATE_INLINE
22 DICTIONARY_CLASS::~dictionary() {
27 RUDIMENTS_TEMPLATE_INLINE
28 bool DICTIONARY_CLASS::setTrackInsertionOrder(
bool trackinsertionorder) {
29 if (!tree.getLength()) {
30 this->trackinsertionorder=trackinsertionorder;
37 RUDIMENTS_TEMPLATE_INLINE
38 bool DICTIONARY_CLASS::getTrackInsertionOrder() {
39 return trackinsertionorder;
43 RUDIMENTS_TEMPLATE_INLINE
44 void DICTIONARY_CLASS::setValue(keytype key, valuetype value) {
51 if (trackinsertionorder) {
58 RUDIMENTS_TEMPLATE_INLINE
59 void DICTIONARY_CLASS::setValues(keytype *keys, valuetype *values) {
61 valuetype *value=values;
63 setValue(*key,*value);
70 RUDIMENTS_TEMPLATE_INLINE
71 void DICTIONARY_CLASS::setValues(keytype
const *keys, valuetype
const *values) {
73 keytype
const *key=keys;
74 valuetype
const *value=values;
76 setValue(*key,*value);
84 RUDIMENTS_TEMPLATE_INLINE
85 void DICTIONARY_CLASS::setValues(keytype *keys, valuetype *values,
89 valuetype *value=values;
90 for (uint64_t i=0; i<count; i++) {
91 setValue(*key,*value);
99 RUDIMENTS_TEMPLATE_INLINE
100 void DICTIONARY_CLASS::setValues(keytype
const *keys, valuetype
const *values,
102 if (keys && values) {
103 keytype
const *key=keys;
104 valuetype
const *value=values;
105 for (uint64_t i=0; i<count; i++) {
106 setValue(*key,*value);
114 RUDIMENTS_TEMPLATE_INLINE
118 *node=dict->
getList()->getFirst();
119 node; node=node->getNext()) {
120 setValue(node->getValue()->getKey(),
121 node->getValue()->getValue());
127 RUDIMENTS_TEMPLATE_INLINE
128 bool DICTIONARY_CLASS::getValue(keytype key, valuetype *value) {
138 RUDIMENTS_TEMPLATE_INLINE
139 valuetype DICTIONARY_CLASS::getValue(keytype key) {
141 if (getValue(key,&value)) {
148 RUDIMENTS_TEMPLATE_INLINE
158 RUDIMENTS_TEMPLATE_INLINE
159 bool DICTIONARY_CLASS::remove(keytype key) {
162 if (trackinsertionorder) {
165 return tree.remove(tnode);
171 RUDIMENTS_TEMPLATE_INLINE
174 *tnode=tree.find(node);
176 if (trackinsertionorder) {
179 return tree.remove(tnode);
185 RUDIMENTS_TEMPLATE_INLINE
186 void DICTIONARY_CLASS::clear() {
188 list.getFirst(); node; node=node->getNext()) {
196 RUDIMENTS_TEMPLATE_INLINE
200 *node=getList()->getFirst(); node; node=node->getNext()) {
207 RUDIMENTS_TEMPLATE_INLINE
213 RUDIMENTS_TEMPLATE_INLINE
215 if (!trackinsertionorder) {
218 *node=tree.getFirst(); node; node=node->getNext()) {
226 RUDIMENTS_TEMPLATE_INLINE
227 void DICTIONARY_CLASS::print() {
229 list.getFirst(); node; node=node->getNext()) {
236 RUDIMENTS_TEMPLATE_INLINE
240 return tree.find(&fnode);
243 #define DICTIONARYNODE_TEMPLATE \ 244 template <class keytype, class valuetype> 246 #define DICTIONARYNODE_CLASS \ 247 dictionarynode<keytype,valuetype> 249 DICTIONARYNODE_TEMPLATE
250 RUDIMENTS_TEMPLATE_INLINE
251 DICTIONARYNODE_CLASS::dictionarynode(keytype key, valuetype value) {
256 DICTIONARYNODE_TEMPLATE
257 RUDIMENTS_TEMPLATE_INLINE
258 DICTIONARYNODE_CLASS::~dictionarynode() {}
260 DICTIONARYNODE_TEMPLATE
261 RUDIMENTS_TEMPLATE_INLINE
262 void DICTIONARYNODE_CLASS::setKey(keytype key) {
266 DICTIONARYNODE_TEMPLATE
267 RUDIMENTS_TEMPLATE_INLINE
268 void DICTIONARYNODE_CLASS::setValue(valuetype value) {
272 DICTIONARYNODE_TEMPLATE
273 RUDIMENTS_TEMPLATE_INLINE
274 keytype DICTIONARYNODE_CLASS::getKey()
const {
278 DICTIONARYNODE_TEMPLATE
279 RUDIMENTS_TEMPLATE_INLINE
280 valuetype DICTIONARYNODE_CLASS::getValue()
const {
284 DICTIONARYNODE_TEMPLATE
285 RUDIMENTS_TEMPLATE_INLINE
286 int32_t DICTIONARYNODE_CLASS::compare(keytype testkey)
const {
287 return node_compare(key,testkey);
290 DICTIONARYNODE_TEMPLATE
291 RUDIMENTS_TEMPLATE_INLINE
292 int32_t DICTIONARYNODE_CLASS::compare(
294 return node_compare(key,testnode->key);
297 DICTIONARYNODE_TEMPLATE
298 RUDIMENTS_TEMPLATE_INLINE
299 void DICTIONARYNODE_CLASS::print()
const {
307 DICTIONARYNODE_TEMPLATE
308 RUDIMENTS_TEMPLATE_INLINE
309 int32_t node_compare(
315 DICTIONARYNODE_TEMPLATE
316 RUDIMENTS_TEMPLATE_INLINE
valuetype getValue() const
size_t printf(const char *format,...)
void setValue(valuetype value)
Definition: linkedlist.h:60
Definition: dictionary.h:12
Definition: dictionary.h:63
linkedlist< dictionarynode< keytype, valuetype > * > * getList()
void append(valuetype value)
Definition: linkedlist.h:11
valuetype getValue() const