Skip to content

Commit 1aaa4ef

Browse files
DOC-5991 rounded out whole page
1 parent 3cb6879 commit 1aaa4ef

File tree

1 file changed

+43
-36
lines changed

1 file changed

+43
-36
lines changed

content/develop/data-types/compare-data-types.md

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,11 @@ types and for very simple collections, you can even use strings. They all allow
245245
basic membership tests, but have different additional features and tradeoffs.
246246
Sorted sets have the highest memory overhead and processing requirements, followed
247247
by sets, and then strings.
248-
Use the considerations below as a guide to choosing the best data type for your task.
248+
Use the decision tree below as a guide to choosing the best data type for your task.
249249
Note that if you need to store extra information for the keys in a set
250250
or sorted set, you can do so with an auxiliary hash or JSON object that has field
251251
names matching the keys in the collection.
252252

253-
1. Do you need to store and retrieve the keys in an arbitrary order or in
254-
lexicographical order?
255-
256-
If so, use **sorted sets** since they are the only collection type that supports ordered iteration.
257-
258-
2. Are the keys always simple integer indices in a known range?
259-
260-
If so, use the bitmap features of **strings** for minimum memory overhead and efficient random access. String bitmaps also support bitwise operations
261-
that are equivalent to set operations such as union, intersection, and difference.
262-
263-
3. For arbitrary string or binary keys, use **sets** for efficient membership tests and
264-
set operations. If you *only* need membership tests on the keys, but you
265-
need to store extra information for each key, consider using **hashes** with
266-
the keys as field names.
267-
268253
```decision-tree
269254
rootQuestion: root
270255
questions:
@@ -286,8 +271,8 @@ questions:
286271
nextQuestion: extraInfo
287272
extraInfo:
288273
text: |
289-
Do you need to store extra information for each key in the collection,
290-
and do you NOT need set operations (union, intersection, difference)?
274+
Do you need to store extra information for each key AND you don't need
275+
set operations (union, intersection, difference)?
291276
whyAsk: |
292277
Hashes allow you to associate data with each key, but they don't support
293278
set operations. If you need both extra data and set operations, sets are not suitable
@@ -323,22 +308,44 @@ questions:
323308

324309
You would normally store sequences of string or binary data using sorted sets,
325310
lists or streams. They each have advantages and disadvantages for particular purposes.
326-
Use the considerations below as a guide to choosing the best data type for your task.
327-
328-
1. Do you frequently need to do any of the following?
329-
330-
- Maintain an arbitrary priority order or lexicographical order of the elements
331-
- Access individual elements or ranges of elements by index
332-
- Perform basic set operations on the elements
333-
334-
If so, use **sorted sets** since they are the only sequence type that supports these
335-
operations directly.
336-
337-
2. Do you need to store and retrieve elements primarily in timestamp order or
338-
manage multiple consumers reading from the sequence?
339-
340-
If so, use **streams** since they are the only sequence type that supports these
341-
features natively.
311+
Use the decision tree below as a guide to choosing the best data type for your task.
342312

343-
3. For simple sequences of string or binary data, use **lists** for efficient
344-
push/pop operations at the head or tail.
313+
```decision-tree
314+
rootQuestion: root
315+
questions:
316+
root:
317+
text: |
318+
Do you need to maintain an arbitrary priority order, lexicographical order,
319+
frequently access elements by index, or perform set operations?
320+
whyAsk: |
321+
Sorted sets are the only sequence type that supports both ordering and set operations.
322+
While lists also support indexing, it is O(n) for lists but O(log n) for sorted sets,
323+
so sorted sets are more efficient if you need frequent index access
324+
answers:
325+
yes:
326+
value: "Yes"
327+
outcome:
328+
label: "Use sorted sets"
329+
id: sortedSetsOutcome
330+
no:
331+
value: "No"
332+
nextQuestion: timestampOrder
333+
timestampOrder:
334+
text: |
335+
Do you need to store and retrieve elements primarily in timestamp order
336+
or manage multiple consumers reading from the sequence?
337+
whyAsk: |
338+
Streams are the only sequence type that supports timestamp-based ordering
339+
and consumer groups for managing multiple readers with at-least-once delivery
340+
answers:
341+
yes:
342+
value: "Yes"
343+
outcome:
344+
label: "Use streams"
345+
id: streamsOutcome
346+
no:
347+
value: "No"
348+
outcome:
349+
label: "Use lists"
350+
id: listsOutcome
351+
```

0 commit comments

Comments
 (0)