Possible Duplicate:
Storing MATLAB structs in Java objects
I'm currently using containers.Map
to associate keys and values in MATLAB. However, quick tests show that this class is really slow compared to java.util.HashMap
. The documentation does not specify the algorithmic complexity for storage and retrieval, so I'm scared it's not using a hash table, and I really need flat performance (O(1) insertion and retrieval).
I've been trying to convert my code using containers.Map
to java.util.HashMap
, but it doesn't work when I try to insert custom MATLAB class instances into the hash map. For instance, given the following class
classdef Bucket < handle
% ... application-specific code ...
end
I can't do this:
m = java.util.HashMap(); % association.
b = Bucket(); % class instance.
k = ...; % some relevant value for association.
m.put(k, b);
It fails with the error message:
??? No method 'put' with matching signature found for class 'java.util.HashMap'.
The exact same code works if I replace b
with some non-custom class, such as:
b = 'foo';
m.put(k, b);
How can I store Bucket
instances in a java.util.HashMap
?