soo i did it like this... i dont think it can get any faster
class trie_map { private: public: class Node { public: Node(){} Node(T d) : d(D){} shared_ptr<T> D; shared_ptr<Node> N[256]; }; shared_ptr<Node> Root; inline trie_map() { Root = shared_ptr<T>(new T(value)); } inline T* find(std::string& s) { shared_ptr<Node> p = Root; int n = s.size(); while (p && n) { p = p->N[int(s[--n])]; } return n ? 0 : p->D.get(); } inline T* insert(std::string& s, T value) { shared_ptr<Node> p = Root; int n = s.size(); while (n) { p = p->N[int(s[--n])]; if (!p) p.reset(new Node); } p->D = shared_ptr<T>(new T(value)); return p->D.get(); } };
unfortunately it doenst work right now... i seem to get some memory error in the instertion function...
and yea it eats alot of memory but i can lower it from 256 possible characters to just the alphabet around 20 characters... which is acceptable
[Edited by - Dragon_Strike on January 7, 2008 5:35:00 PM]