The unified diff between revisions [73dfb720..] and [878203cf..] is displayed below. It can also be downloaded as a raw diff.
#
#
# patch "CMakeLists.txt"
# from [e4757e70830e279d16b02c8c81aac1756f978462]
# to [3a7a37f0632df3ba80cd4ecb9d3b710878a2ecb4]
#
# patch "fritz_server.cc"
# from [a56bd350a43b32a676a2bf03ab4f9cc770fceacc]
# to [2837584fd0ed31f00560e0b44b2568ca205079d3]
#
# patch "tokens.hh"
# from [761ecea77e6476b977b3deadeb87c48d1c2f16d2]
# to [2021d69a582f139f905d4df796a41f002e4626ea]
#
============================================================
--- CMakeLists.txt e4757e70830e279d16b02c8c81aac1756f978462
+++ CMakeLists.txt 3a7a37f0632df3ba80cd4ecb9d3b710878a2ecb4
@@ -4,7 +4,7 @@
find_library (LIB_RT rt)
find_library (LIB_DL dl)
-add_executable (fritz_server fritz.cc tokens.cc fritz_server.cc)
+add_executable (fritz_server fritz.cc fritz_server.cc)
IF (LIB_RT)
target_link_libraries (fritz_server ${LIB_RT} dl)
ENDIF (LIB_RT)
============================================================
--- fritz_server.cc a56bd350a43b32a676a2bf03ab4f9cc770fceacc
+++ fritz_server.cc 2837584fd0ed31f00560e0b44b2568ca205079d3
@@ -6,8 +6,22 @@ main (int argc, char *argv[])
int
main (int argc, char *argv[])
{
- Tokens<unsigned char *> t;
+ Tokens<char *> t;
+ t.add ("hello?");
+ t.add ("my");
+ t.add ("name");
+ t.add ("is");
+ t.add ("bob");
+ t.add ("and");
+ t.add ("I'm");
+ t.add ("and");
+ t.add ("goodbye?");
+ std::cout << t.token_query ("hello?") << std::endl;
+ std::cout << t.token_query ("goodbye?") << std::endl;
+ std::cout << t.token_query ("death?") << std::endl;
+ t.playback ();
+
FritzServer f;
f.run ();
}
============================================================
--- tokens.hh 761ecea77e6476b977b3deadeb87c48d1c2f16d2
+++ tokens.hh 2021d69a582f139f905d4df796a41f002e4626ea
@@ -2,6 +2,8 @@
#define _TOKENS_HH
#include <ext/hash_map>
+#include <vector>
+#include <iostream>
typedef unsigned long int token_t;
@@ -17,22 +19,41 @@ class Tokens {
class Tokens {
private:
token_t last_id;
- __gnu_cxx::hash_map<T, int, __gnu_cxx::hash<T> > token_hash;
+ std::vector<token_t> stash;
+ __gnu_cxx::hash_map<T, token_t, __gnu_cxx::hash<T> > token_to_id;
+ __gnu_cxx::hash_map<token_t, T, __gnu_cxx::hash<token_t> > id_to_token;
public:
Tokens(void) {
-
+ last_id = 0;
}
~Tokens(void) {
-
+
}
- token_t query_token(T query) {
+ token_t token_query(T query) {
+ return token_to_id[query];
}
- token_t add_token(T add) {
+ token_t add(T add) {
+ token_t tid;
+
+ tid = token_to_id[add];
+ if (tid == 0) {
+ tid = token_to_id[add] = ++last_id;
+ id_to_token[tid] = add;
+ }
+ stash.push_back (tid);
+ return tid;
}
+
+ void playback (void) {
+ for (std::vector<token_t>::iterator i=stash.begin(); i!=stash.end(); ++i) {
+ std::cout << *i << " : " << id_to_token[*i] << std::endl;
+ }
+ }
+
};
#endif