60518dcc9812e8b95e2a513839bc5c002ac0d984
[pyutils.git] / docs / pyutils.collectionz.rst
1 pyutils.collectionz package
2 ===========================
3
4 Submodules
5 ----------
6
7 pyutils.collectionz.bidict module
8 ---------------------------------
9
10 The bidict.BiDict class is a subclass of :py:class:`dict` that
11 implements a bidirectional dictionary.  That is, it maps each key to a
12 value in constant time and each value back to the one or more keys it
13 is associated with in constant time.  It does this by simply storing
14 the data twice.
15
16 Sample usage::
17
18     # Initialize with a normal dict...
19     third_party_wierdos = BiDict({
20         'prometheus-fastapi-instrumentator': 'prometheus_fastapi_instrumentator',
21         'scikit-learn': 'sklearn',
22         'antlr4-python3-runtime' : 'antlr4',
23         'python-dateutil': 'dateutil',
24         'speechrecognition': 'speech_recognition',
25         'beautifulsoup4': 'bs4',
26         'python-dateutil': 'dateutil',
27         'homeassistant-api': 'homeassistant_api',
28     })
29
30     # Use in one direction:
31     x = third_party_wierdos['scikit-learn']
32
33     # Use in opposite direction:
34     y = third_party_wierdos.inverse['python_dateutil']
35
36     # Note: type(y) is List since one value may map back to multiple keys.
37
38
39 .. automodule:: pyutils.collectionz.bidict
40    :members:
41    :undoc-members:
42    :show-inheritance:
43
44 pyutils.collectionz.bst module
45 ------------------------------
46
47 The bst.BinarySearchTree class is a binary search tree container.
48
49 .. automodule:: pyutils.collectionz.bst
50    :members:
51    :undoc-members:
52    :show-inheritance:
53
54 pyutils.collectionz.shared\_dict module
55 ---------------------------------------
56
57 The shared\_dict.SharedDict class is a normal python dictionary that
58 can be accessed safely in parallel from multiple threads or processes
59 without (external) locking by using Multiprocessing.SharedMemory.  It
60 uses internal locking and rewrites the shared memory region as it is
61 changed so it is slower than a normal dict.  It also does not grow
62 dynamically; the creator of the shared\_dict must declare a maximum
63 size.
64
65 .. automodule:: pyutils.collectionz.shared_dict
66    :members:
67    :undoc-members:
68    :show-inheritance:
69
70 pyutils.collectionz.trie module
71 -------------------------------
72
73 The trie.Trie class is a Trie or prefix tree.  It can be used with
74 arbitrary sequences as keys and stores its values in a tree with paths
75 determined by the sequence determined by each key.  Thus, it can
76 determine whether a value is contained in the tree via a simple
77 traversal in linear time and can also check whether a key-prefix is
78 present in the tree in linear time.
79
80 .. automodule:: pyutils.collectionz.trie
81    :members:
82    :undoc-members:
83    :show-inheritance:
84
85 Module contents
86 ---------------
87
88 .. automodule:: pyutils.collectionz
89    :members:
90    :undoc-members:
91    :show-inheritance: