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 bool DICTIONARY_CLASS::getValue(keytype key, valuetype *value) {
69 RUDIMENTS_TEMPLATE_INLINE
70 valuetype DICTIONARY_CLASS::getValue(keytype key) {
72 if (getValue(key,&value)) {
79 RUDIMENTS_TEMPLATE_INLINE
89 RUDIMENTS_TEMPLATE_INLINE
90 bool DICTIONARY_CLASS::remove(keytype key) {
93 if (trackinsertionorder) {
96 return tree.remove(tnode);
102 RUDIMENTS_TEMPLATE_INLINE
105 *tnode=tree.find(node);
107 if (trackinsertionorder) {
110 return tree.remove(tnode);
116 RUDIMENTS_TEMPLATE_INLINE
117 void DICTIONARY_CLASS::clear() {
119 list.getFirst(); node; node=node->getNext()) {
127 RUDIMENTS_TEMPLATE_INLINE
131 *node=getList()->getFirst(); node; node=node->getNext()) {
138 RUDIMENTS_TEMPLATE_INLINE
144 RUDIMENTS_TEMPLATE_INLINE
146 if (!trackinsertionorder) {
149 *node=tree.getFirst(); node; node=node->getNext()) {
157 RUDIMENTS_TEMPLATE_INLINE
158 void DICTIONARY_CLASS::print() {
160 list.getFirst(); node; node=node->getNext()) {
167 RUDIMENTS_TEMPLATE_INLINE
171 return tree.find(&fnode);
174 #define DICTIONARYNODE_TEMPLATE \ 175 template <class keytype, class valuetype> 177 #define DICTIONARYNODE_CLASS \ 178 dictionarynode<keytype,valuetype> 180 DICTIONARYNODE_TEMPLATE
181 RUDIMENTS_TEMPLATE_INLINE
182 DICTIONARYNODE_CLASS::dictionarynode(keytype key, valuetype value) {
187 DICTIONARYNODE_TEMPLATE
188 RUDIMENTS_TEMPLATE_INLINE
189 DICTIONARYNODE_CLASS::~dictionarynode() {}
191 DICTIONARYNODE_TEMPLATE
192 RUDIMENTS_TEMPLATE_INLINE
193 void DICTIONARYNODE_CLASS::setKey(keytype key) {
197 DICTIONARYNODE_TEMPLATE
198 RUDIMENTS_TEMPLATE_INLINE
199 void DICTIONARYNODE_CLASS::setValue(valuetype value) {
203 DICTIONARYNODE_TEMPLATE
204 RUDIMENTS_TEMPLATE_INLINE
205 keytype DICTIONARYNODE_CLASS::getKey()
const {
209 DICTIONARYNODE_TEMPLATE
210 RUDIMENTS_TEMPLATE_INLINE
211 valuetype DICTIONARYNODE_CLASS::getValue()
const {
215 DICTIONARYNODE_TEMPLATE
216 RUDIMENTS_TEMPLATE_INLINE
217 int32_t DICTIONARYNODE_CLASS::compare(keytype testkey)
const {
218 return node_compare(key,testkey);
221 DICTIONARYNODE_TEMPLATE
222 RUDIMENTS_TEMPLATE_INLINE
223 int32_t DICTIONARYNODE_CLASS::compare(
225 return node_compare(key,testnode->key);
228 DICTIONARYNODE_TEMPLATE
229 RUDIMENTS_TEMPLATE_INLINE
230 void DICTIONARYNODE_CLASS::print()
const {
238 DICTIONARYNODE_TEMPLATE
239 RUDIMENTS_TEMPLATE_INLINE
240 int32_t node_compare(
246 DICTIONARYNODE_TEMPLATE
247 RUDIMENTS_TEMPLATE_INLINE
size_t printf(const char *format,...)
void setValue(valuetype value)
Definition: linkedlist.h:60
valuetype getValue() const
Definition: dictionary.h:12
void append(valuetype value)
Definition: linkedlist.h:11
valuetype getValue() const