aboutsummaryrefslogtreecommitdiff
path: root/test/containers.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-01-29 18:17:26 +0100
committerSebastian Geerken <devnull@localhost>2013-01-29 18:17:26 +0100
commitd8f1e1bcfa59947b0dabc7a1ec61232d2eb5535e (patch)
tree3c66e1ac29b1bdde68a3087400836f0ab6cf3bc5 /test/containers.cc
parent55671b27e77fe4e95f6ba4e643764c6686e5ce9a (diff)
Some cleanup in HashTable; new container HashSet (of which HashTable is a sub class); fixed a glitch in both (inserting equal node again does not remove the first instance).
Diffstat (limited to 'test/containers.cc')
-rw-r--r--test/containers.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/test/containers.cc b/test/containers.cc
index 9667564e..646624aa 100644
--- a/test/containers.cc
+++ b/test/containers.cc
@@ -4,6 +4,21 @@
using namespace lout::object;
using namespace lout::container::typed;
+void testHashSet ()
+{
+ HashSet<String> h(true);
+
+ h.put (new String ("one"));
+ h.put (new String ("two"));
+ h.put (new String ("three"));
+
+ Iterator<String> it = h.iterator ();
+ while (it.hasNext ()) {
+ String *o = it.getNext ();
+ printf ("%s\n", o->chars());
+ }
+}
+
void testHashTable ()
{
HashTable<String, Integer> h(true, true);
@@ -12,8 +27,17 @@ void testHashTable ()
h.put (new String ("two"), new Integer (2));
h.put (new String ("three"), new Integer (3));
- Iterator<String> it = h.iterator ();
- while (it.hasNext ()) {
+ for (Iterator<String> it = h.iterator (); it.hasNext (); ) {
+ String *k = it.getNext ();
+ Integer *v = h.get (k);
+ printf ("%s -> %d\n", k->chars(), v->getValue());
+ }
+
+ h.put (new String ("one"), new Integer (4));
+ h.put (new String ("two"), new Integer (5));
+ h.put (new String ("three"), new Integer (6));
+
+ for (Iterator<String> it = h.iterator (); it.hasNext (); ) {
String *k = it.getNext ();
Integer *v = h.get (k);
printf ("%s -> %d\n", k->chars(), v->getValue());
@@ -22,6 +46,7 @@ void testHashTable ()
int main (int argc, char *argv[])
{
+ testHashSet ();
testHashTable ();
return 0;