On this page:
4.1.1 To Key or Not to Key
4.1.2 Collection Cheat Sheet
7.7

4.1 Choosing Collections

The modules in rebellion/collection provide a wide selection of different collections. Choosing the right one can be tricky, so this document aims to make that decision easier. Treat this as guidance rather than rules the lines between collection types are blurry and can shift with circumstance.

4.1.1 To Key or Not to Key

The first question you should ask yourself is, do the items of this collection have keys? Can items be looked up by key? If so, you have a dictionary-like collection, also called a bicollection. There are many different kinds of bicollections that vary in whether or not keys are unique, whether entries are unordered, ordered, or sorted, and whether any type of value can serve as a key or only certain types of values. Bicollections can usually be viewed as a collection of key-value entries.

Bicollections

Not bicollections

Hash tables

Lists

Dictionaries

Sets

Multidicts

Multisets

Association lists

Keysets

Records

Tables

4.1.2 Collection Cheat Sheet

Instead of using...

Consider using...

An unordered list with no duplicates

A set

An unordered list

A multiset

A hash whose values are always #true

A set

A hash whose values are nonempty sets

A multidict

A hash whose values are nonempty lists

An association list

A hash whose values are positive integers representing frequencies

A multiset

An unordered list of key-value pairs with no duplicate keys

A hash

An unordered list of key-value pairs

A multidict

A list of key-value pairs where order is significant

An association list

A list or set of keywords or symbols

A keyset

A hash whose keys are symbols or strings

A record

A list of symbol-keyed hashes

A table