Map Data Structures

Discussions compare map implementations like HashMap, TreeMap, and JavaScript's Map across languages such as Java, C++, and JS, focusing on key types, ordering, performance, and use cases versus plain objects.

📉 Falling 0.4x Programming Languages
2,798
Comments
20
Years Active
5
Top Authors
#4623
Topic ID

Activity Over Time

2007
2
2008
8
2009
33
2010
37
2011
56
2012
76
2013
114
2014
191
2015
114
2016
137
2017
170
2018
154
2019
196
2020
220
2021
284
2022
266
2023
242
2024
277
2025
217
2026
4

Keywords

LinkedHashMap JSON L1 WeakMap WeakMaps JavaScript L2 ycombinator.com HashMap JavaScripts map maps hash keys key integer ordered type array lists

Sample Comments

jaffathecake Jul 1, 2021 View on HN

Yeah, Map (or WeakMap if keys are objects and you don't need iteration) is much better at this kind of thing.

bsaul Mar 26, 2025 View on HN

i guess maps and array ? ( if you wanted to reimplement your own in a typesafe way, that is)

kmfrk Jan 31, 2016 View on HN

Some people just prefer hashmaps.

justincormack Sep 7, 2012 View on HN

Maps with non string keys are handled differently even in languages that do support them. Are two instances of an object used as a key the same for example. This may vary depending on the type of the object.

lnanek2 Apr 27, 2014 View on HN

Kind of strange they don't just have a type for that. In Java we have unsorted ones (hashmap), linked ones that retain the sort order (linkedhashmap), and even automatically sorting trees (treemap / sortedmap). Honestly, considering users were relying on the key order being different from the hash order, the default type should have just been made the sorted or linked one and the type added just made unsortedmap or something. Seems like a failing of the language libraries that you have

mixmastamyk Sep 18, 2015 View on HN

Sounds like you need to think a little more about the use case of these maps.

thayne Oct 11, 2022 View on HN

JavaScript also has Map. Which is more general since the keys don't have to be strings.

rurban Mar 26, 2022 View on HN

std::unordered_map is in the similar ballpark. linked lists, oom checks, integer key support.

wejick May 27, 2018 View on HN

You're right it couldn't be true on all the cases In my use case map and array are generally enough.

SJC_Hacker Apr 15, 2024 View on HN

If you want ordering, then a hash-map doesn't help you.