RESP3 icon indicating copy to clipboard operation
RESP3 copied to clipboard

Is map type unordered?

Open kaey opened this issue 6 years ago • 2 comments

Spec suggests encoding json as an example and json is unordered, however it doesn't explicitly states this.

Ordered hash maps would complicate implementation for some languages, like go(map) or python(dict).

kaey avatar Aug 30 '19 18:08 kaey

Just a nit pick:

Ordered hash maps would complicate implementation for some languages, like go(map) or python(dict).

Python 3 dict is ordered. For Go (as well as any other at least a bit widespread language) there is always an ordered map module - see e.g. https://github.com/iancoleman/orderedmap .

dumblob avatar Aug 30 '19 18:08 dumblob

Maps represent a sequence of field-value items, basically what we could call a dictionary data structure, or in other terms, an hash.

The theoretical datastructure 'hash' and 'dictionary' are unordered - of course some implementations do have orderings fall-out as a side-effect (insert order, usually).

I think there should be no guarantee of order made by RESP3, as this would require Redis or any other implementer of RESP3 to always return the same ordering for a map and make implementing a client tricky in a language where the 'logical' native map type to return is not ordered (for example, Go maps, Python 2 dicts) - you would either depend on a non-standard library that provides an ordered map, or ditch the ordering and return your native unordered type.

AngusP avatar Nov 21 '19 11:11 AngusP