A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
Here's a little benchmark of Associative Arrays and Dynamic Arrays. I'm showing traversal and lookup speed. The `static this()` is used to create a random collection of words which get stored in the two arrays: https://gist.github.com/893340 Hash lookups are naturally very fast. So I am incline

Re: A case for valueless AA's?

2011-03-29 Thread dsimcha
== Quote from Andrej Mitrovic (n...@none.none)'s article > Here's a little benchmark of Associative Arrays and Dynamic Arrays. I'm > showing traversal and lookup speed. The `static this()` is used to create a random collection of words which get stored in the two arrays: > https://gist.github.com/

Re: A case for valueless AA's?

2011-03-29 Thread Piotr Szturmaj
Andrej Mitrovic wrote: 1. I'm wasting memory. I don't need the values, I only need the keys. But I can't declare a void[string] hash. But I don't know how to get rid of the values, which leaves the issue #1. Maybe static array of zero length? From documentation: "A static array with a dimensi

Re: A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
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 mi

Re: A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
Oh there's a container? I'll take a look, thanks guys.

Re: A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
Looks like not. I've misread Piotr'es post. :)

Re: A case for valueless AA's?

2011-03-29 Thread bearophile
Piotr Szturmaj: > void[0][string] aa; > aa["key"] = []; > assert("key" in aa); Nice. I have done a benchmark, and it seems a void[0][int] uses the same amount of memory as a int[int]. I have not tried a void[0][string]. Bye, bearophile

Re: A case for valueless AA's?

2011-03-29 Thread Nick Sabalausky
"Andrej Mitrovic" wrote in message news:imtirq$292g$1...@digitalmars.com... > Here's a little benchmark of Associative Arrays and Dynamic Arrays. I'm > showing traversal and lookup speed. The `static this()` is used to create > a random collection of words which get stored in the two arrays: >

Re: A case for valueless AA's?

2011-03-29 Thread spir
On 03/29/2011 11:47 PM, Andrej Mitrovic wrote: Looks like not. I've misread Piotr'es post. :) There is one in Steven's dcollections. Denis -- _ vita es estrany spir.wikidot.com

Re: A case for valueless AA's?

2011-03-29 Thread spir
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) resul

Re: A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
On 3/30/11, spir wrote: > On 03/29/2011 11:47 PM, Andrej Mitrovic wrote: >> Looks like not. I've misread Piotr'es post. :) > > There is one in Steven's dcollections. > > Denis Oh yes, I've been meaning to look at dcollections. The last time I saw it I was still confused as to how templates work,

Re: A case for valueless AA's?

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 14:34, dsimcha wrote: > == Quote from Andrej Mitrovic (n...@none.none)'s article > > > Here's a little benchmark of Associative Arrays and Dynamic Arrays. I'm > > showing > > traversal and lookup speed. The `static this()` is used to create a random > > collection of words which ge

Re: A case for valueless AA's?

2011-03-29 Thread dsimcha
On 3/29/2011 8:37 PM, Jonathan M Davis wrote: We now have std.container.RedBlackTree, which can be used as a set, but it is a tree rather than a hash table. - Jonathan M Davis This isn't a very good set. It doesn't even support basic set primitives like intersection, difference, union, etc.

Re: A case for valueless AA's?

2011-03-29 Thread Andrej Mitrovic
I had a look at dcollections, it seems to have a few different implementations of a set. And it has intersection (not sure about difference or union). It's boost licensed, I wonder if Steve will make a push of his library to Phobos when its done..

Re: A case for valueless AA's?

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 20:11, Andrej Mitrovic wrote: > I had a look at dcollections, it seems to have a few different > implementations of a set. And it has intersection (not sure about > difference or union). It's boost licensed, I wonder if Steve will make > a push of his library to Phobos when its done..

Re: A case for valueless AA's?

2011-03-30 Thread spir
On 03/30/2011 05:02 AM, dsimcha wrote: On 3/29/2011 8:37 PM, Jonathan M Davis wrote: We now have std.container.RedBlackTree, which can be used as a set, but it is a tree rather than a hash table. - Jonathan M Davis This isn't a very good set. It doesn't even support basic set primitives like

Re: A case for valueless AA's?

2011-03-30 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 23:02:35 -0400, dsimcha wrote: On 3/29/2011 8:37 PM, Jonathan M Davis wrote: We now have std.container.RedBlackTree, which can be used as a set, but it is a tree rather than a hash table. - Jonathan M Davis This isn't a very good set. It doesn't even support basic set

Re: A case for valueless AA's?

2011-03-30 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 23:11:53 -0400, Andrej Mitrovic wrote: I had a look at dcollections, it seems to have a few different implementations of a set. And it has intersection (not sure about difference or union). It's boost licensed, I wonder if Steve will make a push of his library to Phobos wh

Re: A case for valueless AA's?

2011-03-30 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 18:42:59 -0400, bearophile wrote: Piotr Szturmaj: void[0][string] aa; aa["key"] = []; assert("key" in aa); Nice. I have done a benchmark, and it seems a void[0][int] uses the same amount of memory as a int[int]. I have not tried a void[0][string]. Each node in the

Re: A case for valueless AA's?

2011-03-30 Thread David Nadlinger
On 3/30/11 5:02 AM, dsimcha wrote: […] Furthermore, most programs will probably want a hash set. First of all, I agree that we really want to have a hash set in Phobos. I think that a first implementation wouldn't even need to support advanced operations like union, intersection, etc., but we

Re: A case for valueless AA's?

2011-03-30 Thread dsimcha
== Quote from David Nadlinger (s...@klickverbot.at)'s article > On 3/30/11 5:02 AM, dsimcha wrote: > > […] Furthermore, most programs will probably want a hash set. > First of all, I agree that we really want to have a hash set in Phobos. > I think that a first implementation wouldn't even need to

Re: A case for valueless AA's?

2011-03-30 Thread David Nadlinger
On 3/30/11 3:59 PM, dsimcha wrote: == Quote from David Nadlinger (s...@klickverbot.at)'s article On 3/30/11 5:02 AM, dsimcha wrote: […] Furthermore, most programs will probably want a hash set. First of all, I agree that we really want to have a hash set in Phobos. I think that a first impleme

Re: A case for valueless AA's?

2011-03-30 Thread Jonathan M Davis
On 2011-03-30 07:42, David Nadlinger wrote: > On 3/30/11 3:59 PM, dsimcha wrote: > > == Quote from David Nadlinger (s...@klickverbot.at)'s article > > > >> On 3/30/11 5:02 AM, dsimcha wrote: > >>> […] Furthermore, most programs will probably want a hash set. > >> > >> First of all, I agree that w