4 #include <rudiments/stdio.h> 5 #include <rudiments/private/nodeinlines.h> 7 #define DICTIONARY_TEMPLATE \ 8 template <class keytype, class valuetype> 10 #define DICTIONARY_CLASS \ 11 dictionary<keytype,valuetype> 15 DICTIONARY_CLASS::dictionary() {
16 trackinsertionorder=
true;
21 DICTIONARY_CLASS::~dictionary() {
27 bool DICTIONARY_CLASS::setTrackInsertionOrder(
bool trackinsertionorder) {
28 if (!tree.getLength()) {
29 this->trackinsertionorder=trackinsertionorder;
37 bool DICTIONARY_CLASS::getTrackInsertionOrder() {
38 return trackinsertionorder;
43 void DICTIONARY_CLASS::setValue(keytype key, valuetype value) {
50 if (trackinsertionorder) {
58 void DICTIONARY_CLASS::setValues(keytype *keys, valuetype *values) {
60 valuetype *value=values;
62 setValue(*key,*value);
70 void DICTIONARY_CLASS::setValues(keytype
const *keys, valuetype
const *values) {
72 keytype
const *key=keys;
73 valuetype
const *value=values;
75 setValue(*key,*value);
84 void DICTIONARY_CLASS::setValues(keytype *keys, valuetype *values,
88 valuetype *value=values;
89 for (uint64_t i=0; i<count; i++) {
90 setValue(*key,*value);
99 void DICTIONARY_CLASS::setValues(keytype
const *keys, valuetype
const *values,
101 if (keys && values) {
102 keytype
const *key=keys;
103 valuetype
const *value=values;
104 for (uint64_t i=0; i<count; i++) {
105 setValue(*key,*value);
117 *node=dict->
getList()->getFirst();
118 node; node=node->getNext()) {
119 setValue(node->getValue()->getKey(),
120 node->getValue()->getValue());
127 bool DICTIONARY_CLASS::getValue(keytype key, valuetype *value) {
138 valuetype DICTIONARY_CLASS::getValue(keytype key) {
140 if (getValue(key,&value)) {
158 bool DICTIONARY_CLASS::remove(keytype key) {
161 if (trackinsertionorder) {
165 return tree.remove(tnode);
174 *tnode=tree.find(node);
176 if (trackinsertionorder) {
180 return tree.remove(tnode);
187 void DICTIONARY_CLASS::clear() {
189 list.getFirst(); node; node=node->getNext()) {
198 void DICTIONARY_CLASS::clearAndDelete() {
200 list.getFirst(); node; node=node->getNext()) {
202 delete node->
getValue()->getValue();
211 void DICTIONARY_CLASS::clearAndArrayDelete() {
213 list.getFirst(); node; node=node->getNext()) {
214 delete[] node->
getValue()->getKey();
215 delete[] node->
getValue()->getValue();
224 void DICTIONARY_CLASS::clearAndDeleteKeys() {
226 list.getFirst(); node; node=node->getNext()) {
236 void DICTIONARY_CLASS::clearAndArrayDeleteKeys() {
238 list.getFirst(); node; node=node->getNext()) {
239 delete[] node->
getValue()->getKey();
248 void DICTIONARY_CLASS::clearAndDeleteValues() {
250 list.getFirst(); node; node=node->getNext()) {
251 delete node->
getValue()->getValue();
260 void DICTIONARY_CLASS::clearAndArrayDeleteValues() {
262 list.getFirst(); node; node=node->getNext()) {
263 delete[] node->
getValue()->getValue();
272 void DICTIONARY_CLASS::clearAndDeleteKeysAndArrayDeleteValues() {
274 list.getFirst(); node; node=node->getNext()) {
276 delete[] node->
getValue()->getValue();
285 void DICTIONARY_CLASS::clearAndArrayDeleteKeysAndDeleteValues() {
287 list.getFirst(); node; node=node->getNext()) {
288 delete[] node->
getValue()->getKey();
289 delete node->
getValue()->getValue();
301 *node=getList()->getFirst(); node; node=node->getNext()) {
316 if (!trackinsertionorder) {
319 *node=tree.getFirst(); node; node=node->getNext()) {
328 void DICTIONARY_CLASS::print() {
330 list.getFirst(); node; node=node->getNext()) {
341 return tree.find(&fnode);
344 #define DICTIONARYNODE_TEMPLATE \ 345 template <class keytype, class valuetype> 347 #define DICTIONARYNODE_CLASS \ 348 dictionarynode<keytype,valuetype> 350 DICTIONARYNODE_TEMPLATE
352 DICTIONARYNODE_CLASS::dictionarynode(keytype key, valuetype value) {
357 DICTIONARYNODE_TEMPLATE
359 DICTIONARYNODE_CLASS::~dictionarynode() {}
361 DICTIONARYNODE_TEMPLATE
363 void DICTIONARYNODE_CLASS::setKey(keytype key) {
367 DICTIONARYNODE_TEMPLATE
369 void DICTIONARYNODE_CLASS::setValue(valuetype value) {
373 DICTIONARYNODE_TEMPLATE
375 keytype DICTIONARYNODE_CLASS::getKey()
const {
379 DICTIONARYNODE_TEMPLATE
381 valuetype DICTIONARYNODE_CLASS::getValue()
const {
385 DICTIONARYNODE_TEMPLATE
387 int32_t DICTIONARYNODE_CLASS::compare(keytype testkey)
const {
388 return node_compare(key,testkey);
391 DICTIONARYNODE_TEMPLATE
393 int32_t DICTIONARYNODE_CLASS::compare(
395 return node_compare(key,testnode->key);
398 DICTIONARYNODE_TEMPLATE
400 void DICTIONARYNODE_CLASS::print()
const {
408 DICTIONARYNODE_TEMPLATE
410 int32_t node_compare(
416 DICTIONARYNODE_TEMPLATE
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