construct a DoubleDict from a Map

This commit is contained in:
Ben Fry
2018-05-07 18:33:52 -04:00
parent 9015177fb2
commit 70db057aef

View File

@@ -3,6 +3,7 @@ package processing.data;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import processing.core.PApplet;
@@ -106,6 +107,20 @@ public class DoubleDict {
}
public DoubleDict(Map<String, Double> incoming) {
count = incoming.size();
keys = new String[count];
values = new double[count];
int index = 0;
for (Map.Entry<String, Double> e : incoming.entrySet()) {
keys[index] = e.getKey();
values[index] = e.getValue();
indices.put(keys[index], index);
index++;
}
}
/**
* @webref doubledict:method
* @brief Returns the number of key/value pairs