SetTrie
settrie.SetTrie
Result(iter_id)
Container holding the results of several operations of SetTrie. It behaves, basically, like an iterator.
Source code in settrie/SetTrie.py
44 45 |
|
SetTrie(binary_image=None)
Mapping container for efficient storage of key-value pairs where the keys are sets. Uses an efficient trie implementation. Supports querying for values associated to subsets or supersets of stored key sets.
Example
>>> from mercury.dynamics.SetTrie import SetTrie
>>> s = SetTrie()
>>> s.insert({2,3}, 'id1')
>>> s.insert({2,3,4}, 'id2')
Source code in settrie/SetTrie.py
73 74 75 76 77 |
|
__getstate__()
Used by pickle.dump() (See https://docs.python.org/3/library/pickle.html)
Source code in settrie/SetTrie.py
82 83 84 85 |
|
__setstate__(state)
Used by pickle.load() (See https://docs.python.org/3/library/pickle.html)
Source code in settrie/SetTrie.py
87 88 89 90 91 |
|
find(set)
Finds the ID of the set matching the one provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set |
Set for searching |
required |
Returns:
Type | Description |
---|---|
str
|
id of the set with the exact match. An empty string if no match was found. |
Source code in settrie/SetTrie.py
102 103 104 105 106 107 108 109 110 |
|
insert(set, id)
Inserts a new set into a SetTrie object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set |
Set
|
Set to add |
required |
id |
str
|
String representind the ID for the test |
required |
Source code in settrie/SetTrie.py
93 94 95 96 97 98 99 100 |
|
load_from_binary_image(binary_image)
Load the state of the c++ SetTrie object from a binary_image returned by a previous save_as_binary_image() call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
binary_image |
A list of strings returned by save_as_binary_image() |
required |
Returns:
Type | Description |
---|---|
True on success, destroys, initializes and returns false on failure. |
Source code in settrie/SetTrie.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
save_as_binary_image()
Saves the state of the c++ SetTrie object as a Python list of strings referred to a binary_image.
Returns:
Type | Description |
---|---|
The binary_image containing the state of the SetTrie. There is |
|
not much you can do with it except serializing it as a Python |
|
(e.g., pickle) object and loading it into another SetTrie object. |
|
Pass it to the constructor to create an initialized object, |
Source code in settrie/SetTrie.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
subsets(set)
Find all the subsets for a given set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set |
set for which we want to find all the supersets |
required |
Returns:
Type | Description |
---|---|
Result
|
Iterator object with the IDs of the matching subsets. |
Source code in settrie/SetTrie.py
123 124 125 126 127 128 129 130 131 132 |
|
supersets(set)
Find all the supersets of a given set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set |
set for which we want to find all the supersets |
required |
Returns:
Type | Description |
---|---|
Result
|
Iterator object with the IDs of the matching supersets. |
Source code in settrie/SetTrie.py
112 113 114 115 116 117 118 119 120 121 |
|