comparison anagram/support/sparse.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 1993-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * sparse.h
7 */
8
9 #ifndef SPARSE_H
10 #define SPARSE_H
11
12 #include "agbaltree.h"
13
14 class AgSparseIntArray {
15 public:
16 struct Pair {
17 int key;
18 int value;
19 Pair(int k, int v = 0) : key(k), value(v) {}
20 int operator < (const Pair &p) const { return key < p.key; }
21 };
22
23 protected:
24 AgBalancedTree<Pair> tree;
25
26 public:
27 AgSparseIntArray() {}
28 ~AgSparseIntArray() {}
29 int &operator [] (int k) {
30 Pair pair(k), *pointer = &pair;
31 tree.identify(pointer);
32 return pointer->value;
33 }
34 void reset() { tree.reset(); }
35 };
36
37
38 #endif /* SPARSE_H */