Skip to content

Commit 3cb6879

Browse files
DOC-5991 added Collections tree
1 parent 3465c30 commit 3cb6879

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,65 @@ names matching the keys in the collection.
260260
If so, use the bitmap features of **strings** for minimum memory overhead and efficient random access. String bitmaps also support bitwise operations
261261
that are equivalent to set operations such as union, intersection, and difference.
262262

263-
3. For arbitrary string or binary keys, use **sets** for efficient membership tests and
263+
3. For arbitrary string or binary keys, use **sets** for efficient membership tests and
264264
set operations. If you *only* need membership tests on the keys, but you
265265
need to store extra information for each key, consider using **hashes** with
266266
the keys as field names.
267267

268+
```decision-tree
269+
rootQuestion: root
270+
questions:
271+
root:
272+
text: |
273+
Do you need to store and retrieve the keys in an arbitrary order or in
274+
lexicographical order?
275+
whyAsk: |
276+
Sorted sets are the only collection type that supports ordered iteration,
277+
which is essential if you need to access elements in a specific order
278+
answers:
279+
yes:
280+
value: "Yes"
281+
outcome:
282+
label: "Use sorted sets"
283+
id: sortedSetsOutcome
284+
no:
285+
value: "No"
286+
nextQuestion: extraInfo
287+
extraInfo:
288+
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)?
291+
whyAsk: |
292+
Hashes allow you to associate data with each key, but they don't support
293+
set operations. If you need both extra data and set operations, sets are not suitable
294+
answers:
295+
yes:
296+
value: "Yes"
297+
outcome:
298+
label: "Use hashes"
299+
id: hashesOutcome
300+
no:
301+
value: "No"
302+
nextQuestion: integerIndices
303+
integerIndices:
304+
text: |
305+
Are the keys always simple integer indices in a known range?
306+
whyAsk: |
307+
String bitmaps provide minimum memory overhead and efficient random access
308+
for integer indices, with bitwise operations equivalent to set operations
309+
answers:
310+
yes:
311+
value: "Yes"
312+
outcome:
313+
label: "Use strings (bitmaps)"
314+
id: stringsOutcome
315+
no:
316+
value: "No"
317+
outcome:
318+
label: "Use sets"
319+
id: setsOutcome
320+
```
321+
268322
### Sequences
269323

270324
You would normally store sequences of string or binary data using sorted sets,

static/js/decision-tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
const topMargin = 10;
158158
const indentWidth = 40; // Increased from 24 for wider indent
159159
const boxPadding = 12; // Increased from 8 for more padding
160-
const maxBoxWidth = 360; // Increased from 280 for wider boxes
160+
const maxBoxWidth = 420; // Increased to accommodate longer questions
161161
const maxCharsPerLine = Math.floor(maxBoxWidth / charWidth);
162162

163163
// Calculate box dimensions for each item
@@ -174,7 +174,7 @@
174174
maxDepth = Math.max(maxDepth, item.depth);
175175
});
176176

177-
const svgWidth = leftMargin + (maxDepth + 1) * indentWidth + 320;
177+
const svgWidth = leftMargin + (maxDepth + 1) * indentWidth + maxBoxWidth + 40;
178178
const svgHeight = topMargin + items.reduce((sum, item) => sum + item.boxHeight + 20, 0) + 10;
179179

180180
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

0 commit comments

Comments
 (0)