ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/FAS/src/keylist.h
Revision: 70
Committed: Tue Aug 13 22:33:51 2002 UTC (21 years, 11 months ago) by tim
Content type: text/plain
File size: 1943 byte(s)
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 tim 70 /**********************************************************************
2     * Copyright (C) 2002-2003 by Gezelter's Group
3     *This program is free software; you can redistribute it and/or modify
4     *it under the terms of the GNU General Public License as published by
5     *the Free Software Foundation version 2 of the License.
6     *
7     *This program is distributed in the hope that it will be useful,
8     *but WITHOUT ANY WARRANTY; without even the implied warranty of
9     *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10     *GNU General Public License for more details.
11     *
12     ************************************************************************
13     *Author: Teng Lin Email: tlin@nd.edu
14     *Date: 08/13/2002 Version: 1.0
15     *
16     ************************************************************************
17     *Description:
18     *
19     ***********************************************************************/
20    
21     #ifndef keylistH
22     #define keylistH
23     #include <iostream>
24     #include <vector>
25     #include <string>
26     #include <hash_map>
27    
28     using namespace std;
29    
30     template<class T1,class T2, class THashFcn, class TEqualKey> class TKeyList
31     {
32     private:
33     vector<T1> _keys;
34     vector<T2> _data;
35     hash_map<T1, int, THashFcn, TEqualKey> _hashTable;
36     int _num;
37    
38     public:
39     TKeyList();
40     ~TKeyList();
41    
42     int AddKey(T1 key, T2 data);
43     int GetIndex(T1 key);
44    
45     const T2& GetDataByKey(string &str) const;
46     const T2& GetDataByIndex(int index) const;
47     const T1& GetKeyByIndex(int index) const;
48    
49     void SetDataByIndex(int index, T2 data);
50     void SetDataByKey(T1 key, T2 data);
51     void ChangeKey(int index, T1 key);
52     void ChangeKey(T1 oldKey, T1 newKey);
53    
54     };
55    
56     struct TEqstr
57     {
58     bool operator()(const string *s1, string *s2) const
59     {
60     return *s1 == *s2;
61     }
62     };
63    
64    
65     typedef TKeyList<string, int, hash<string>, equal_to<string> > TNameList;
66    
67    
68    
69    
70    
71    
72     //---------------------------------------------------------------------------
73     #endif