Closed KaKi87 closed 1 year ago
Would this make sense ?
Sure, but not in the context of a generic data structure library, sorry :)
Note that people would use an array or an object/map also based on the time complexity they need for the lookup. find is O(n) while getting an object/map key is O(1) and this makes a huge difference in most use cases.
Sure, but not in the context of a generic data structure library, sorry :)
That's already something : I needed to know that this isn't a bad idea.
find is O(n) while getting an object/map key is O(1)
That's why I mentioned a Map
-based implementation, which I'll show you once done.
Thanks !
Hi !
xvZwiCpi
Nzd9UsGT
QiDXP2wA
JpYeAY7H
I can store these in an array :
Thus access them the same way by ID :
And by properties :
Or I can store these in an object :
Thus more easily access properties by ID :
But more hardly access ID by properties :
I could duplicate IDs :
To slightly simplify that previous line :
But what if a single variable type could allow doing both operations easily ?
Does that exist ?
If not, I'm thinking about implementing it that way :
In which case I'd put it in a lib, but how would this be named ?
I'd also make a second implementation that would enforce ID uniqueness and use
Map
to map IDs with indexes instead of runningfind
: while the first implementation would be fine for static data, the second one would be more suitable for dynamic data.Would this make sense ?
Thanks