Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/agmap.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * agmap.h | |
7 */ | |
8 | |
9 #ifndef AGMAP_H | |
10 #define AGMAP_H | |
11 | |
12 #include "agbaltree.h" | |
13 | |
14 | |
15 template <class Key, class Value> | |
16 class AgMap { | |
17 public: | |
18 class Wrapper { | |
19 public: | |
20 Key key; | |
21 Value value; | |
22 int operator < (const Wrapper &w) const { return key < w.key; } | |
23 Wrapper(const Key &k, const Value &v) : key(k), value(v) {} | |
24 }; | |
25 | |
26 AgBalancedTree<Wrapper> tree; | |
27 friend class AgBalancedTree<Wrapper>; | |
28 | |
29 public: | |
30 Value &operator [] (const Key &k); | |
31 int includes(const Key &k, Value &v); | |
32 }; | |
33 | |
34 template <class Key, class Value> | |
35 Value &AgMap<Key,Value>::operator [] (const Key &k) { | |
36 Wrapper wrapper(k, Value()); | |
37 Wrapper *result = &wrapper; | |
38 tree.identify(result); | |
39 return result->value; | |
40 } | |
41 | |
42 template <class Key, class Value> | |
43 int AgMap<Key,Value>::includes(const Key &k, Value &v) { | |
44 Wrapper wrapper(k,v); | |
45 Wrapper *result = &wrapper; | |
46 int flag = tree.identify(result); | |
47 v = result->value; | |
48 return flag; | |
49 } | |
50 | |
51 | |
52 #endif /* AGMAP_H */ |