Re: Find in assoc array then iterate

2022-10-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/22/22 12:53 AM, Kevin Bailey wrote: Steven, Just because you don't see the value doesn't mean I don't. You should try to be more helpful, or don't bother. I just mean that I don't understand what iterating from a random position in the AA is. Why not iterate from the beginning? It

Re: Find in assoc array then iterate

2022-10-22 Thread Kevin Bailey via Digitalmars-d-learn
ah, I knew that I could iterate over byKey, but I didn't know that it was a tangible thing, that you could hold in your hand. This should be fine, and I'll use your template trick for passing it to a function. Thanks Paul and Ali!

Re: Find in assoc array then iterate

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 08:21, Kevin Bailey wrote: > his claim that there was no value. I think he was questioning the need for iterating from a point forward inside an unordered container. When the container is unordered, the elements that are accessed after a found element could be anything. I think

Re: Find in assoc array then iterate

2022-10-22 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 22 October 2022 at 15:21:07 UTC, Kevin Bailey wrote: OTOH, a forward iterator (i.e. copyable but does not need to go backwards) solves the problem elegantly and efficiently. The builtin function [`byKeyValue`][1] returns a forward range (D's version of a forward iterator) over

Re: Find in assoc array then iterate

2022-10-22 Thread Kevin Bailey via Digitalmars-d-learn
Siarhei, Thanks for this possibility. I didn't know D had "pointers" like this. Unfortunately, it appears that you can't pick up where you left off with that pointer? You have to re-scan forward? bachmeier, I didn't reply to Steven's question; I replied to his claim that there was no

Re: Find in assoc array then iterate

2022-10-22 Thread Tejas via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite

Re: Find in assoc array then iterate

2022-10-22 Thread bachmeier via Digitalmars-d-learn
On Saturday, 22 October 2022 at 04:53:09 UTC, Kevin Bailey wrote: Steven, Just because you don't see the value doesn't mean I don't. You should try to be more helpful, or don't bother. Programs are written to do things that have value. Programming languages are designed to support that

Re: Find in assoc array then iterate

2022-10-22 Thread Siarhei Siamashka via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite

Re: Find in assoc array then iterate

2022-10-21 Thread Kevin Bailey via Digitalmars-d-learn
Hi Sergey, While the unordered map doesn't guarantee an ordering (since its contents are hashed), the order should remain static if you don't insert or delete. Hi JG, Thanks for the red-black tree reference. I'll read up on it in case I need it but I'd prefer to use the built-in O(1) hash

Re: Find in assoc array then iterate

2022-10-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/21/22 6:03 PM, Kevin Bailey wrote: I'm trying to do this equivalent C++:     unordered_map map;     for (auto i = map.find(something); i != map.end(); ++i)     ...do something with i... in D, but obviously with an associative array. It seems that it's quite easy to iterate

Re: Find in assoc array then iterate

2022-10-21 Thread Ali Çehreli via Digitalmars-d-learn
On 10/21/22 15:03, Kevin Bailey wrote: I'm trying to do this equivalent C++:     unordered_map map;     for (auto i = map.find(something); i != map.end(); ++i)     ...do something with i... in D, but obviously with an associative array. It seems that it's quite easy to iterate through

Re: Find in assoc array then iterate

2022-10-21 Thread JG via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite

Re: Find in assoc array then iterate

2022-10-21 Thread Sergey via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite

Find in assoc array then iterate

2022-10-21 Thread Kevin Bailey via Digitalmars-d-learn
I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite easy to iterate through the whole "map", but not start from the