bug fixing on Dict and List classes, add Iterable constructor

This commit is contained in:
Ben Fry
2013-05-01 14:54:54 -04:00
parent 2bc1cce04d
commit f8d25375cc
7 changed files with 37 additions and 1 deletions
+4
View File
@@ -70,6 +70,9 @@ public class FloatDict {
this.keys = keys;
this.values = values;
count = keys.length;
for (int i = 0; i < count; i++) {
indices.put(keys[i], i);
}
}
@@ -81,6 +84,7 @@ public class FloatDict {
/** Remove all entries. */
public void clear() {
count = 0;
indices = new HashMap<String, Integer>();
}
+7
View File
@@ -29,6 +29,13 @@ public class FloatList implements Iterable<Float> {
}
public FloatList(Iterable<Float> iter) {
this(10);
for (float v : iter) {
append(v);
}
}
/**
* Improve efficiency by removing allocated but unused entries from the
+4
View File
@@ -93,6 +93,9 @@ public class IntDict {
this.keys = keys;
this.values = values;
count = keys.length;
for (int i = 0; i < count; i++) {
indices.put(keys[i], i);
}
}
@@ -104,6 +107,7 @@ public class IntDict {
/** Remove all entries. */
public void clear() {
count = 0;
indices = new HashMap<String, Integer>();
}
+8
View File
@@ -39,6 +39,14 @@ public class IntList implements Iterable<Integer> {
}
public IntList(Iterable<Integer> iter) {
this(10);
for (int v : iter) {
append(v);
}
}
/**
* Improve efficiency by removing allocated but unused entries from the
* internal array used to store the data. Set to private, though it could
+4
View File
@@ -68,6 +68,9 @@ public class StringDict {
this.keys = keys;
this.values = values;
count = keys.length;
for (int i = 0; i < count; i++) {
indices.put(keys[i], i);
}
}
@@ -79,6 +82,7 @@ public class StringDict {
/** Remove all entries. */
public void clear() {
count = 0;
indices = new HashMap<String, Integer>();
}
+9
View File
@@ -29,6 +29,15 @@ public class StringList implements Iterable<String> {
}
// Create from something iterable, for instance:
// StringList list = new StringList(hashMap.keySet());
public StringList(Iterable<String> iter) {
this(10);
for (String s : iter) {
append(s);
}
}
/**
* Improve efficiency by removing allocated but unused entries from the
+1 -1
View File
@@ -3391,7 +3391,7 @@ public class Table {
public StringDict getStringDict(int keyColumn, int valueColumn) {
return new StringDict(getStringColumn(keyColumn),
getStringColumn(valueColumn));
getStringColumn(valueColumn));
}