]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/assoc.hh
release: 0.0.40
[lilypond.git] / flower / assoc.hh
index 84a54c9a72bb4a61fc86e3da89adff02130973a3..99e20914b7aa31094643cd59533844772d668e54 100644 (file)
@@ -1,23 +1,31 @@
 #ifndef ASSOC_HH
 #define ASSOC_HH
 
-#include "vray.hh"
+#include "varray.hh"
+#include <assert.h>
 
-template<class K,class V>
+/**
+  A helper for Assoc
+ */
+template<class K, class V>
 struct Assoc_ent_ {
     bool free;
     K key;
     V val;
 };
 
+
+/** mindblowingly stupid Associative array implementation.
+  Hungarian: map
+ */
 template<class K, class V>
 struct Assoc {
-    svec< Assoc_ent_<K,V> > arr;
+    Array< Assoc_ent_<K,V> > arr;
 
-    /****************/
+    /* ************** */
     
     int find(K key) const {
-       for (int i = 0; i < arr.sz(); i++) {
+       for (int i = 0; i < arr.size(); i++) {
            if (!arr[i].free && key == arr[i].key)
                return i;
        }
@@ -25,7 +33,7 @@ struct Assoc {
     }
     int find_creat(K key) {
        int free = -1;
-       for (int i = 0; i < arr.sz(); i++) {
+       for (int i = 0; i < arr.size(); i++) {
            if (key == arr[i].key) {            
                return i;
            } else if (arr[i].free ) {
@@ -41,8 +49,8 @@ struct Assoc {
        Assoc_ent_<K,V> ae;
        ae.free = false;
        ae.key = key;
-       arr.add(ae);
-       return arr.sz() -1;
+       arr.push(ae);
+       return arr.size() -1;
     }
 public:
     bool elt_query(K key) const {
@@ -58,9 +66,6 @@ public:
        int i = find_creat(key);
        arr[i].val = val;
     }
-    /**
-    should create "set" template
-    */
     V& operator[](K key) {
        return arr[find_creat(key)].val;
     }
@@ -68,8 +73,6 @@ public:
        assert(elt_query(key));
        return arr[find(key)].val;
     }
-
 };
-/** mindblowingly stupid Associative array implementation
- */
+
 #endif