1 |
/********************************************************************** |
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 |
void Clear(); |
39 |
public: |
40 |
TKeyList(); |
41 |
~TKeyList(); |
42 |
|
43 |
int AddKey(T1 key, T2 &data); |
44 |
int GetIndex(T1 key); |
45 |
|
46 |
const T2& GetDataByKey(string &str) const; |
47 |
const T2& GetDataByIndex(int index) const; |
48 |
const T1& GetKeyByIndex(int index) const; |
49 |
|
50 |
void SetDataByIndex(int index, T2 &data); |
51 |
void SetDataByKey(T1 key, T2 &data); |
52 |
void ChangeKey(int index, T1 newKey); |
53 |
void ChangeKey(T1 oldKey, T1 newKey); |
54 |
|
55 |
}; |
56 |
|
57 |
typedef TKeyList<string, int, hash<string>, equal_to<string> > TNameList; |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
//--------------------------------------------------------------------------- |
65 |
#endif |