Skip to content

Commit 6489fec

Browse files
authored
Add brief features list on main page (#294)
1 parent 3a83be0 commit 6489fec

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

docs/index.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# pysorteddict
22

33
Enriches Python with `SortedDict`, a sorted dictionary: a dictionary in which the keys are always in ascending order.
4+
They are not sorted when queried; they are genuinely stored such that iterating over them yields a monotonically
5+
increasing sequence. Needless to say, a given `SortedDict` instance only admits keys of a single type with a strict
6+
ordering defined.
47

58
pysorteddict is implemented entirely in C++. `SortedDict` provides a Python interface to `std::map`.
69

@@ -29,3 +32,45 @@ desired, though.
2932
[[![changelog](_static/images/changelog.svg)<br>Changelog](changelog)]{.card}
3033
[[![development](_static/images/development.svg)<br>Development](development)]{.card}
3134
]{.card-container}
35+
36+
## Why pysorteddict?
37+
38+
There are many sorted dictionary implementations for Python. Foremost among them is Sorted Containers, a mature library
39+
which has seen use in real-world applications. (It also provides sorted list and set implementations, but those aren't
40+
in the scope of pysorteddict.) So why use the sorted dictionary from pysorteddict instead of Sorted Containers?
41+
42+
pysorteddict has some rather attractive features which Sorted Containers does not have.
43+
44+
### Strongly Typed
45+
46+
Keys are not automatically converted between compatible types. For instance, although `0 == 0.0` in Python, a sorted
47+
dictionary with integer keys will reject `0.0`.
48+
49+
The sorted dictionary from Sorted Containers allows mixing integer and float keys.
50+
51+
### Strict
52+
53+
Conceptually different keys are considered different. For instance, although `0 == False` in Python, a sorted
54+
dictionary with integer keys will not fetch the value mapped to `0` when queried with `False`.
55+
56+
The sorted dictionary from Sorted Containers inherits Python's default behaviour, treating `0` as `False` and `1` as
57+
`True`.
58+
59+
### Correct
60+
61+
NaN is unconditionally rejected as a key.
62+
63+
The sorted dictionary from Sorted Containers accepts NaN, resulting in an order of keys which cannot truly be
64+
considered sorted. Subsequent reorderings will place NaN in arbitrary positions.
65+
66+
### Stable Under Mutation During Iteration
67+
68+
Modifications to a sorted dictionary are allowed while iterating over it, and the results are consistent and
69+
well-defined.
70+
71+
The sorted dictionary from Sorted Containers also allows modifications while iterating over it, but the results are
72+
clearly wrong: for instance, an iterator over it will keep yielding keys even after the dictionary is cleared.
73+
74+
### Robust
75+
76+
Computations are relegated to the robust C++ sorted dictionary.

0 commit comments

Comments
 (0)