1(****************************************************************************
2*Copyright 2008
3*  Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
4****************************************************************************)
5(****************************************************************************
6* This file is part of Teyjus.
7*
8* Teyjus is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation, either version 3 of the License, or
11* (at your option) any later version.
12*
13* Teyjus is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16* GNU General Public License for more details.
17*
18* You should have received a copy of the GNU General Public License
19* along with Teyjus.  If not, see <http://www.gnu.org/licenses/>.
20****************************************************************************)
21(**********************************************************************
22*Table:
23* Tables implemented using balanced binary trees.
24**********************************************************************)
25module OrderedSymbol =
26struct
27  type t = Symbol.symbol
28  let compare =
29    fun s1 s2 ->
30      if((Symbol.id s1) < (Symbol.id s2)) then
31        -1
32      else if((Symbol.id s1) > (Symbol.id s2)) then
33        1
34      else
35        0
36end
37
38module SymbolTable = Map.Make(OrderedSymbol)
39type 'a symboltable = 'a SymbolTable.t
40
41let find =
42  fun k table ->
43    try
44      let v = SymbolTable.find k table in
45      Some v
46    with Not_found -> None
47
48let add = fun k v table ->
49  (SymbolTable.add k v table)
50
51let iter = fun f table ->
52  (SymbolTable.iter f table)
53
54let fold = fun f v table ->
55  (SymbolTable.fold f v table)
56
57let empty = SymbolTable.empty
58
59
60let printTable toStringFunc table =
61  let printFunc s ent =
62    print_endline (toStringFunc s ent)
63  in
64  SymbolTable.iter printFunc table
65
66