February 21, 2002 Re: Array slicing Associative and Rectangular arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Pavel Minayev wrote: > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3C75179F.EF2FE1BF@deming-os.org... > > > Is the result of strcmp() defined or implementation dependent? If the > > former, then strcmp()'s comparison algorithm would work fine for me.... > > Don't forget that D associative arrays don't necessary have string keys. It's perfectly valid to have an int, float, or even Object as a key. Great! But I didn't know that...and I don't see it in the online docs. The closest I see is a statement that "Associated arrays are supported for all following types", which is hard to understand, but I guessed meant "you can have an associative array (keyed by strings) of any type". > Also, any "comparison algorithm" sorta limits the implementation - it either has to store the keys in that order in memory, or the iteration process will be quite slow (because a look-up is performed for each key in the table). How do you implement an ordered scan for a hash table, for example? Right. It would be nice to be able to slice these arrays with compiler support in the language. I don't really care the underlying algorithm; I was just hoping that I could have access to the easy functionality. However if more than strings are supported, then it gets hard. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
February 21, 2002 Re: Array slicing Associative and Rectangular arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3C753CF5.D4313464@deming-os.org... > Great! But I didn't know that...and I don't see it in the online docs. The > closest I see is a statement that "Associated arrays are supported for all following types", which is hard to understand, but I guessed meant "you can > have an associative array (keyed by strings) of any type". Just remember the syntax: int[char[]] foo; // keys are char[] char[][double] bar; // keys are double Object[Object] baz; // keys are Object The only thing is that currently DMD alpha only supports int[char[]] =) I guess this also includes pointers since they're 32-bit as well (or am I wrong, Walter?). |
February 21, 2002 Re: Array slicing Associative and Rectangular arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Karl Bochert | "Karl Bochert" <kbochert@ix.netcom.com> wrote in message news:1105_1014316952@bose... > > I believe there's no such thing as "rectangular slice" in D. start[1..4] is an array of 3 elements of type int[5]. > > Is that the second through fourth elements of start? > Or the first through third? Second through fourth (counting from 1). > Neither seems to be what [1..4] is saying! > [1..4] clearly shows either a 1 and a 4 or a 'first' and a 'fourth' > inside the brackets (array). C (and D) arrays are zero-based, you know =) So the element isn't actually 'first', but 'zeroth'. |
Copyright © 1999-2021 by the D Language Foundation