Added a short tutorial on using graphs.
13 template <typename G, typename K, typename KIt>
14 class ArrayMapFactory {
23 template <typename V, typename A = allocator<V> >
24 class Map : public MapBase<G, K, KIt> {
27 typedef typename _Alloc_traits<V, A>::_Alloc_type _Alloc_type;
30 Map() : values(0), capacity(0) {}
32 Map(Graph& g, MapRegistry<G, K, KIt>& r)
33 : MapBase<G, K, KIt>(g, r) {
35 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
36 int id = graph->id(it);
47 while (capacity <= max_id) {
50 Value* values = reinterpret_cast<Value*>(new char[capacity*sizeof(Value)]);
51 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
52 int id = graph->id(it);
53 new(&(values[id])) Value();
55 cerr << capacity << endl;
60 delete[] reinterpret_cast<char*>(values);
66 Value& operator[](const K& key) {
67 int id = graph->id(key);
71 const Value& operator[](const K& key) const {
72 int id = graph->id(key);
76 const Value& get(const K& key) const {
77 int id = graph->id(key);
81 void set(const K& key, const Value& val) {
82 int id = graph->id(key);
86 void add(const K& key) {
87 cerr << capacity << endl;
88 int id = graph->id(key);
90 int new_capacity = (capacity == 0 ? 1 : capacity);
91 while (new_capacity <= id) {
94 Value* new_values = reinterpret_cast<Value*>(new char[new_capacity*sizeof(Value)]);;
95 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
96 int jd = graph->id(it);
98 new(&(new_values[jd])) Value(values[jd]);
101 if (capacity != 0) delete[] reinterpret_cast<char *>(values);
103 capacity = new_capacity;
105 cerr << id << ' ' << capacity << endl;
106 new(&(values[id])) Value();
109 void erase(const K& key) {
110 int id = graph->id(key);