2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $XConsortium: Dict.cc /main/3 1996/06/11 16:42:15 cde-hal $
26 #include "DictIter.hh"
27 #include "DictLink.hh"
33 template<class K, class V>
41 template<class K, class V>
49 template<class K, class V>
60 template<class K, class V>
61 Dict<K,V>::Dict() : def_key(kdef()), def_val(vdef()), head(NULL)
67 template<class K, class V>
68 Dict<K,V>::Dict(const K& k, const V& v) : def_key(k), def_val(v), head(NULL)
73 template<class K, class V>
81 template<class K, class V>
83 Dict<K,V>::element(const K& k)
85 (void) operator[](k); // move current to k
86 return DictIter<K,V>(this, current);
89 template<class K, class V>
93 return DictIter<K,V>(this, head);
96 template<class K, class V>
98 Dict<K,V>::operator[](const K& k)
101 current = head = new DictLink<K,V>(k, def_val);
102 current->pre = current->suc = NULL;
104 return current->value;
107 DictLink<K,V>* p = head;
109 if (p->key == k) { // found
111 return current->value;
114 if (k < p->key) { // insert before p
115 current = new DictLink<K,V>(k, def_val);
116 current->pre = p->pre;
121 p->pre->suc = current;
124 return current->value;
127 DictLink<K,V>* s = p->suc;
129 current = new DictLink<K,V>(k, def_val);
134 return current->value;