field ordering in octave's save/load

Jaroslav Hajek highegg at gmail.com
Tue Mar 3 23:39:03 CST 2009


On Wed, Mar 4, 2009 at 4:14 AM, Sergei Steshenko <sergstesh at yahoo.com> wrote:
>
>
>
>
> --- On Tue, 3/3/09, Gunnar Rätsch <Gunnar.Raetsch at tuebingen.mpg.de> wrote:
>
>> From: Gunnar Rätsch <Gunnar.Raetsch at tuebingen.mpg.de>
>> Subject: field ordering in octave's save/load
>> To: bug at octave.org
>> Date: Tuesday, March 3, 2009, 12:39 PM
>> Dear octave team,
>>
>> I've been using octave a lot recently and am really
>> happy with its
>> recent progress. Thanks a lot for your efforts!
>>
>> I came across one issue today, which isn't really a
>> bug, but just a
>> different behaviour compared to matlab, which you may want
>> to fix (at
>> least it would help me quite a bit).
>> I've noticed that when structures are saved and then
>> loaded again in
>> octave, then the fields are alphabetically sorted. This is
>> not the
>> case in matlab.
>> I had a piece of code that depended on the ordering of
>> these fields
>> and therefore the octave code failed, while the matlab code
>> worked
>> just fine (this was a difficult-to-find bug).
>>
>> What do you think? Do you intend to change the code such
>> that the
>> field order is preserved?
>>
>> Thanks a lot in advance,
>>
>> Gunnar
>>
>
> IIRC, structs are hashes, struct fields are hash keys, and typically hash
> keys order cannot be relied upon, i.e. one has to use a special (not the
> simplest) implementation of hashes in order to preserve hash keys order.
>

Not really so. Structs are implemented using std::map, which is
usually something like a binary tree.
I think a hash implementation of map would not satisfy certain
complexity requirements imposed by the C++ standard.


> So, does Matlab promise hash keys order in your scenario ?
>
> If yes, then it's a bug in 'octave', if not - then it's a bug in your code
> - it relies on an undocumented feature.
>
> Regards,
>  Sergei.



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



More information about the Bug-octave mailing list