[1]: https://gobyexample.com/maps [2]: https://docs.python.org/3/tutorial/datastructures.html#dicti... [3]: https://learn.microsoft.com/en-us/dotnet/api/system.collecti...
While the basic data structure is obviously identical to its counterparts, the way it interacts with the ecosystem as a whole makes it feel way more powerful. The interaction of hashes, symbols, and blocks lead to a language which feels like it is designed with DSLs as first-class citizens. This leads to things like Ruby on Rails, which at first glance feels like pure magic.
I get a somewhat similar feeling about lists in Python. Because of its very extensive list comprehension you start thinking in lists, leading to some very clean code which would be extremely awkward to implement in many other languages.
Totally agree.
I've noticed a lot of novice-level posts on here lately. Although I admit the post was very well written.
* Hashtable
* SortedList
* SortedList<TKey, TValue>
* Dictionary<TKey, TValue>
* ConcurrentDictionary<TKey, TValue>
I don't even know C# (just Java), yet I know that you'd probably want to use Dictionary<TKey, TValue> most of the time.
It's a doubly linked list, array, hashmap all in one, with some weird magic when handling numeric indices.
There's often the time when using another language that I made a bad choice by picking either an array or hash or list while later I need one of the other properties PHP would give me by default. The extra cost for most uses is neglectible.
In what way, exactly, is PHP's associative array (a hash table of course, like all these things) a doubly linked list ?
Sure, in a language which isn't very fast anyway, I can believe it's reasonable to use your hashtable as an array, O(1)~ or O(1)* [Expected or Amortized constant time] probably feels enough like 1 [a single operation] in this language that you shouldn't worry about it. Explaining to beginners why they can't write digits["four"] is more trouble than it's worth, so how about just make it work instead.
It is a hashmap, so, that makes sense. These are different words for essentially the same type.
But how is it a doubly linked list ?
But the old implementation had pointers to next and last (previous) element in the list: https://github.com/php/php-src/blob/PHP-5.3/Zend/zend_hash.h...
While internally this is indeed using linked lists, I don't think you can make use of that from PHP which is what I'd imagined was meant. Suppose I had a million integers that I found somewhere, and then I want to splice in a different million integers I have, so that in total there are two million integers. With linked lists that's very cheap, basically instant, but with most data structure, including a hash table, not so much.
Linked Lists are very rarely what you needed, even though when they are what you needed they're invaluable. They are really easy to implement in C, so it's sort of a "I've got a hammer, now all I see are nails" situation in C.
And it's true, on modern hardware linked list are often bad due to data locality making iteration bad ... but that data structure was designed before (while, as said, revamped meanwhile ...)
But it's quite fancy. If you deal with it with "proper" indexed keys data will be packed in an array (or vector, ifyou prefer C++ terms; while most data stored in there is just pointers taking away some benefit of the packing...) while also keeping the doubly-linked-list pointers and once you have holes in it or string keys or something it plays hash and gives away some of the ordered storage ...
In the end that extra bookkeeping everywhere makes it slow and bloated for everything, but from a usage perspective it's quite nice.