3 ms·
Rather than storing data structures directly in the hashmap, I would store them in an array and map the keys to array indexes. Then the types of the hashmaps w
by porlw 13y ago
Rather than storing data structures directly in the hashmap, I would store them in an array and map the keys to array indexes.
Then the types of the hashmaps would all be the same (all map key->integer), and I could develop reusable procs for each set operation.
- willvarfar 13y agoWouldn't that mean an extra level of indirection while dereferencing?
- dded 13y agoYes, but so does run-time generics somewhere along the line.
- sepeth 13y agoReally? AFAIK, compiler creates those functions/classes from corresponding generics (it is called templates in C++, and it really acts like template in C++). Hence, they are compile time. I believe, it is the same in Java, too: http://docs.oracle.com/javase/tutorial/java/generics/erasure.html http://docs.oracle.com/javase/tutorial/java/generics/erasure...
- dded 13y agoWell, yes, compile-time generics are compile-time. That's why I said "runtime".
- willvarfar 13y agoYes, but you are recommending he do that in Go, so by having an extra array lookup you'd be further slowing down the Go program, which he says is 5x slower than the Java program already.
- sigmaml 13y ago> Rather than storing data structures directly in the hashmap, I would store them in an array and map the keys to array indexes. Author of the blog post here. That is one of the reasons I shifted to using bit sets: specific element types can be elided.