Skip to content

Commit ed6d8da

Browse files
committed
Expand documentation on the ordering of lists and maps
1 parent ca3a596 commit ed6d8da

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

modules/ROOT/pages/syntax/operators.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,14 @@ For example, `1 > b` and `1 < b` are both false when b is NaN.
407407
*** xref::queries/expressions.adoc#boolean[`BOOLEAN`]
408408
*** Numbers: xref::queries/expressions.adoc#numerical[`INTEGER`, `FLOAT`]
409409
** The value `null` is ordered after all other values.
410-
* *Ordering* of constructed type values:
411-
** For the xref::values-and-types/property-structural-constructed.adoc#constructed-types[constructed types] (e.g. maps and lists), elements of the containers are compared pairwise for ordering and thus determine the ordering of two container types.
412-
For example, `[1, 'foo', 3]` is ordered before `[1, 2, 'bar']` since `'foo'` is ordered before `2`.
413-
410+
* *Ordering* of xref::values-and-types/property-structural-constructed.adoc#constructed-types[constructed type] values:
411+
** Lists are compared in dictionary order, also known as lexicographic order:
412+
*** Elements are compared pairwise from the start of the list to the end. The order of the two lists is defined by the order of the first pair where the two elements differ. For example, `[1, 'foo', 3]` is less than `[1, 2, 'bar']` since `'foo'` is less than `2`.
413+
*** If a list is shorter than the other one, it is padded with the empty element which is considered to be less than any other value (including null values). For example, `[1, 'foo']` is less than `[1, 'foo', 3]`, and `[1]` is less than `[1, null]`.
414+
** Maps are ordered by size, keys, and values:
415+
*** Maps are primarily compared by size: the smallest map is the one with the smallest number of entries. For example `{a: 1}` is less than `{a: 0, b: 'foo'}`.
416+
*** The order of maps of equal size are then defined by comparing their respective lists of keys sorted in alphabetical order. For example `{b: 100, a: 'foo'}` is less than `{a: '', c: null}` since `['a', 'b']` is less than `['a', 'c']`.
417+
*** Finally, the order of maps with identical key sets is based on comparing their values pairwise, having first sorted the entries by keys in alphabetical order. For example `{b: 100, a: 'foo'}` is less than `{a: 'foo', b: null}` since `['foo', 100]` is less than `['foo', null]`.
414418

415419
[[cypher-operations-chaining]]
416420
=== Chaining comparison operations

0 commit comments

Comments
 (0)