Adding first code drop
[demorecorder] / src / SimpleHashMap.vala
diff --git a/src/SimpleHashMap.vala b/src/SimpleHashMap.vala
new file mode 100644 (file)
index 0000000..f8445be
--- /dev/null
@@ -0,0 +1,67 @@
+/*  Demo Recorder for MAEMO 5
+*   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
+*   This program is free software; you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License version 2,
+*   or (at your option) any later version, as published by the Free
+*   Software Foundation
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details
+*
+*   You should have received a copy of the GNU General Public
+*   License along with this program; if not, write to the
+*   Free Software Foundation, Inc.,
+*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+namespace IdWorks {
+
+public class SimpleHashMap<T> : Object {
+
+  List<string> _keys;
+  List<T> _values;
+  
+  public List<string> keys {
+    get {
+      return _keys;
+    }
+  }
+  
+  public List<T> values {
+    get {
+      return _values;
+    }
+  }
+  
+  construct {
+    _keys = new List<string>();
+    _values = new List<T>();
+  }
+  
+  public new void set(string key, T val) {
+    for (int idx = 0; idx < _keys.length(); ++idx) {
+      if (key == _keys.nth_data(idx)) {
+        // delete value at idx
+        _values.delete_link(_values.nth(idx));
+        // insert value at idx
+        _values.insert(val, idx);
+        return;
+      }
+    }
+    _keys.append(key);
+    _values.append(val);
+  }
+  
+  public new T get(string key) {
+    for (int idx = 0; idx < _keys.length(); ++idx) {
+      if (key == _keys.nth_data(idx)) {
+        return _values.nth_data(idx);
+      }
+    }
+    return null;
+  }
+  
+}
+
+}
\ No newline at end of file