Re: Associative Arrays max length? 32bit/64bit

2014-05-27 Thread Steven Schveighoffer via Digitalmars-d
On Mon, 26 May 2014 19:03:22 -0400, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, May 24, 2014 at 11:54:47PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May 2014 21:39:14 -0700, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On

Re: Associative Arrays max length? 32bit/64bit

2014-05-26 Thread H. S. Teoh via Digitalmars-d
On Sat, May 24, 2014 at 11:54:47PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May 2014 21:39:14 -0700, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, May 24, 2014 at 06:05:49PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May

Re: Associative Arrays max length? 32bit/64bit

2014-05-25 Thread Steven Schveighoffer via Digitalmars-d
On Sat, 24 May 2014 21:39:14 -0700, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, May 24, 2014 at 06:05:49PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May 2014 02:54:01 -0700, FG h...@fgda.pl wrote: [...] Really? Then what does

Re: Associative Arrays max length? 32bit/64bit

2014-05-25 Thread via Digitalmars-d
On Sunday, 25 May 2014 at 06:54:47 UTC, Steven Schveighoffer wrote: Any object/struct that defines opCmp but not opEquals is broken, and deserves to not work with AAs. If this is the case, then it needs to be documented in http://dlang.org/operatoroverloading.html (I'm not seeing it there),

Re: Associative Arrays max length? 32bit/64bit

2014-05-25 Thread John Colvin via Digitalmars-d
On Sunday, 25 May 2014 at 06:54:47 UTC, Steven Schveighoffer wrote: On Sat, 24 May 2014 21:39:14 -0700, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, May 24, 2014 at 06:05:49PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May 2014 02:54:01 -0700,

Re: Associative Arrays max length? 32bit/64bit

2014-05-25 Thread Steven Schveighoffer via Digitalmars-d
On Sun, 25 May 2014 03:19:37 -0700, Marc Schütz schue...@gmx.net wrote: On Sunday, 25 May 2014 at 06:54:47 UTC, Steven Schveighoffer wrote: Any object/struct that defines opCmp but not opEquals is broken, and deserves to not work with AAs. If this is the case, then it needs to be documented

Re: Associative Arrays max length? 32bit/64bit

2014-05-25 Thread Steven Schveighoffer via Digitalmars-d
On Sun, 25 May 2014 04:59:43 -0700, John Colvin john.loughran.col...@gmail.com wrote: On Sunday, 25 May 2014 at 06:54:47 UTC, Steven Schveighoffer wrote: It's a trivial change to add opEquals when opCmp is defined. Perhaps I'm being naïve, but can't we just have a default compiler

Re: Associative Arrays max length? 32bit/64bit

2014-05-24 Thread FG via Digitalmars-d
Bloody Thunderbird. I think I pressed Reply instead of Followup. Sorry, Steven. On 2014-05-19 15:31, Steven Schveighoffer wrote: No, in that DMD file, the bucket is a tree, not a doubly-linked list. Silly me. A look at the body of delnodes should have made it clear that it's a binary tree.

Re: Associative Arrays max length? 32bit/64bit

2014-05-24 Thread Steven Schveighoffer via Digitalmars-d
On Sat, 24 May 2014 02:54:01 -0700, FG h...@fgda.pl wrote: Bloody Thunderbird. I think I pressed Reply instead of Followup. Sorry, Steven. It's OK, it went into my spam folder anyway ;) On 2014-05-19 15:31, Steven Schveighoffer wrote: No, in that DMD file, the bucket is a tree, not a

Re: Associative Arrays max length? 32bit/64bit

2014-05-24 Thread H. S. Teoh via Digitalmars-d
On Sat, May 24, 2014 at 06:05:49PM -0700, Steven Schveighoffer via Digitalmars-d wrote: On Sat, 24 May 2014 02:54:01 -0700, FG h...@fgda.pl wrote: [...] Really? Then what does TypeInfo.compare(void*, void*) use? For example here: auto key_hash = keyti.getHash(pkey); Entry *e; /*

Re: Associative Arrays max length? 32bit/64bit

2014-05-19 Thread Steven Schveighoffer via Digitalmars-d
On Sat, 17 May 2014 16:18:07 -0400, FG h...@fgda.pl wrote: On 2014-05-17 21:35, bearophile wrote: FG: and don't forget the extra memory needed to store the tree for fast key look-up in the hash array. I think D now uses a linked list for the collision chains (so opCmp is useless,

Re: Associative Arrays max length? 32bit/64bit

2014-05-18 Thread monarch_dodra via Digitalmars-d
On Saturday, 17 May 2014 at 22:05:03 UTC, bearophile wrote: monarch_dodra: for a sorted linked list (or forward iterators in general), you can find the result with O(N) *walk* iterations, but still only O(log(N)) *comparison* iterations. I think I have never implement such algorithm, but

Re: Associative Arrays max length? 32bit/64bit

2014-05-18 Thread bearophile via Digitalmars-d
monarch_dodra: It's not used in phobos (as far as I know of anyways). It *could* be implemented in SortedRange's BinaryFind though. Recently SortedRanges were changed, now they don't need to be random access ranges, so this is possible and I think it's good:

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread via Digitalmars-d
On Saturday, 17 May 2014 at 00:25:13 UTC, sdvcn wrote: import std.stdio; import std.utf; import std.uni; import std.string; import std.random; import std.conv; int main(string[] argv) { size_t[string] bary; try{ for(size_t i=0;i(size_t.max -1);i++)

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread sdvcn via Digitalmars-d
On Saturday, 17 May 2014 at 09:26:32 UTC, Marc Schütz wrote: On Saturday, 17 May 2014 at 00:25:13 UTC, sdvcn wrote: import std.stdio; import std.utf; import std.uni; import std.string; import std.random; import std.conv; int main(string[] argv) { size_t[string] bary; try{

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread sdvcn via Digitalmars-d
int main(string[] argv) { auto flog = File(results.txt, w); size_t[string] bary; for(size_t i=0;i(size_t.max -1);i++) { bary[Key: ~ to!(string)(i)] = i; flog.write(stop i= ~text(i)); flog.seek(0);

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread FG via Digitalmars-d
On 2014-05-17 12:46, sdvcn wrote: int main(string[] argv) { auto flog = File(results.txt, w); size_t[string] bary; for(size_t i=0;i(size_t.max -1);i++) { bary[Key: ~ to!(string)(i)] = i; flog.write(stop i= ~text(i)); flog.seek(0);

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread bearophile via Digitalmars-d
FG: and don't forget the extra memory needed to store the tree for fast key look-up in the hash array. I think D now uses a linked list for the collision chains (so opCmp is useless, despite it's still required for the hashing protocol). Bye, bearophile

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread FG via Digitalmars-d
On 2014-05-17 21:35, bearophile wrote: FG: and don't forget the extra memory needed to store the tree for fast key look-up in the hash array. I think D now uses a linked list for the collision chains (so opCmp is useless, despite it's still required for the hashing protocol). Indeed, I

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread bearophile via Digitalmars-d
FG: and each bucket points to an ordered double-linked list. That list is walked left or right depending on what value Typeinfo::compare returns for two keys. Hmm... isn't opCmp used by that function? Why useless? Sorry, I didn't know the linked list is sorted. It's scanned sequentially,

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread FG via Digitalmars-d
On 2014-05-17 22:30, bearophile wrote: Sorry, I didn't know the linked list is sorted. It's scanned sequentially, because you can't use a binary search on a regular linked list. Perhaps a skiplist is better to avoid O(n^2) behavour in presence of attacks or degenerate cases (in past the AA

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread monarch_dodra via Digitalmars-d
On Saturday, 17 May 2014 at 20:30:30 UTC, bearophile wrote: Sorry, I didn't know the linked list is sorted. It's scanned sequentially, because you can't use a binary search on a regular linked list. Perhaps a skiplist is better to avoid O(n^2) behavour in presence of attacks or degenerate

Re: Associative Arrays max length? 32bit/64bit

2014-05-17 Thread bearophile via Digitalmars-d
monarch_dodra: for a sorted linked list (or forward iterators in general), you can find the result with O(N) *walk* iterations, but still only O(log(N)) *comparison* iterations. I think I have never implement such algorithm, but you are right, and it's nice. Is Phobos using this idea

Associative Arrays max length? 32bit/64bit

2014-05-16 Thread sdvcn via Digitalmars-d
import std.stdio; import std.utf; import std.uni; import std.string; import std.random; import std.conv; int main(string[] argv) { size_t[string] bary; try{ for(size_t i=0;i(size_t.max -1);i++) { bary[Key: ~