[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: associative array
From: |
Andrew Janke |
Subject: |
Re: associative array |
Date: |
Thu, 26 Mar 2020 16:33:22 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 |
On 3/26/20 4:25 PM, José Abílio Matos wrote:
> On Thursday, 26 March 2020 20.00.39 WET Francesco Potortì wrote:
>
>> I need an associative array, and I tried with structs, with the field
>
>> names as keys.
>
>>
>
>> Unfortunately it clearly slows down with size. I have about 30000 keys,
>
>> for each I first check if it's already there, if not I create it, if
>
>> it's there I add some data. The number of operations (insertion +
>
>> updates) is around 55000. The slowdown appears to be quadratic (but I
>
>> have not made any measurement, in fact).
>
>>
>
>> Are there more efficient ways to build and update an associative array?
>
>
>
> How about containers.Map:
>
> https://octave.org/doc/v5.2.0/containers_002eMap.html
That's a reasonable idea, but I'm curious as to why struct itself is
slow. I would think that struct lookups for get or set would be O(1)
using a hash on the string key (or some other symbol-level identifier).
Are structs not hashtables over the string key values?
Cheers,
Andrew