From: gg on
Dear All,

I have implemented a look-up table using "containers.Map". I need to index into this Map with 40-by-1 vectors of type "uint32" or "double". I am doing this vectorised so my indices come as matrices like "idxvec", a 40-by-n matrix of n indices.

What I did:
Since Map only supports scalar-types or char arrays, I transform the matrix of index vectors. For example to initialise the Map I use the command:

tmp = char(idxvec + 1)';
idxcellarr = mat2cell(tmp,ones(size(tmp,1),1),size(tmp,2));
myMap = containers.Map( idxcellarr, someData, 'uniformvalues', true);

I use the same transformation from idxvec to idxcellarr to access the values in myMap.

My problem:
The big weakness of this solution is that "char" limits the size of entries in idxvec to the maximum size of 65535.

My Question:
1. Is there a better, less limited, way of transforming idxvec into a cell array of char arrays or more generally to access the values in myMap?
2. Is there a better way than Map of implementing a very high dimensional, yet very sparse, look-up table?

My thoughts:
A possible solution might be using C (Mex-files) to do the conversion. I have never done this before so I fear the large initial amount to invest in learning the headers, setting up a C-compiler and so on.

Maybe I could implement a hash-table myself. But again: I have not done this before, so this might be a lot of work with low success probabilities.

Any advice? What do you think?

Thanks a lot in advance
gg
From: Ashish Uthama on
I am sure there is a better way.

This is the best I can think of right now:

>> numKeys = {[1:10],[20:30]}

numKeys =

[1x10 double] [1x11 double]

>> value = {'one-ten','twenty-thirty'}

value =

'one-ten' 'twenty-thirty'


>> charKeys = cellfun(@(e)sprintf('%d',e),numKeys,'UniformOutput',false);
>> m = containers.Map(charKeys, value);


>> lookUpKey = [20:30];
>> m(sprintf('%d',lookUpKey))

ans =

twenty-thirty
From: gg on
Thank you Ashish,

yes this works. But when I tried this on larger index sets (a few hundred thousands), I found sprintf to be orders of magnitude slower than char. This is why I went for char in spite of its limitation.

Kind regards
Guido

"Ashish Uthama" <first.last(a)mathworks.com> wrote in message <op.ved8t8zaa5ziv5(a)uthamaa.dhcp.mathworks.com>...
> I am sure there is a better way.
>
> This is the best I can think of right now:
>
> >> numKeys = {[1:10],[20:30]}
>
> numKeys =
>
> [1x10 double] [1x11 double]
>
> >> value = {'one-ten','twenty-thirty'}
>
> value =
>
> 'one-ten' 'twenty-thirty'
>
>
> >> charKeys = cellfun(@(e)sprintf('%d',e),numKeys,'UniformOutput',false);
> >> m = containers.Map(charKeys, value);
>
>
> >> lookUpKey = [20:30];
> >> m(sprintf('%d',lookUpKey))
>
> ans =
>
> twenty-thirty