A case for valueless AA's?
spir
denis.spir at gmail.com
Tue Mar 29 16:42:33 PDT 2011
On 03/29/2011 11:43 PM, Andrej Mitrovic wrote:
> A use case for this could be a file system search:
>
> void[string] names; // unique names to find
> string[] results;
>
> foreach (string name; dirEntries(curdir, SpanMode.deep))
> {
> if (name.basename in names)
> results ~= name;
> }
>
> With string arrays the `if` check might slow things down.
There are tons of use cases for sets. Unfortunately, implementation (either as
hashed collections or binary trees) is far more complicated than for sequential
collections (array, list). Especially, it highly depends on the element type.
Thus, sets are rarely a builtin type.
For this reason, probably, people often wrongly use arrays/lists where sets are
appropriate. This means, mainly, where the primary operation is a test of
membership/containment. (Also set operations like set equality, union,
intersection...)
The pseudo-value trick you used stil a good one: people often build sets from
AAs with a value of true for each key/element (thus, set[x] returns true if x
is present in set -- but this works only in implementations where absence of x
does not throw).
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list