Represents a potentially sparse array in FoundationDB.
| 107 | |
| 108 | |
| 109 | class Vector: |
| 110 | """Represents a potentially sparse array in FoundationDB.""" |
| 111 | |
| 112 | # Public functions |
| 113 | |
| 114 | def __init__(self, subspace, defaultValue=''): |
| 115 | self.subspace = subspace |
| 116 | self.defaultValue = defaultValue |
| 117 | self.local = threading.local() |
| 118 | self.local.tr = None |
| 119 | |
| 120 | def use_transaction(self, tr): |
| 121 | """ |
| 122 | Get an object that can be used in a with statement to perform operations |
| 123 | on this vector without supplying a transaction as an argument to each operation. |
| 124 | |
| 125 | For example: |
| 126 | |
| 127 | with vector.use_transaction(tr): |
| 128 | vector[0] = 1 |
| 129 | vector.push(1) |
| 130 | ... |
| 131 | """ |
| 132 | return _ImplicitTransaction(self, tr) |
| 133 | |
| 134 | def size(self, tr=None): |
| 135 | """Get the number of items in the Vector. This number includes the sparsely represented items.""" |
| 136 | return self._size(self._to_transaction(tr)) |
| 137 | |
| 138 | def push(self, val, tr=None): |
| 139 | """Push a single item onto the end of the Vector.""" |
| 140 | self._push(val, self._to_transaction(tr)) |
| 141 | |
| 142 | def back(self, tr=None): |
| 143 | """Get the value of the last item in the Vector.""" |
| 144 | return self._back(self._to_transaction(tr)) |
| 145 | |
| 146 | def front(self, tr=None): |
| 147 | """Get the value of the first item in the Vector.""" |
| 148 | return self._get(0, self._to_transaction(tr)) |
| 149 | |
| 150 | def pop(self, tr=None): |
| 151 | """Get and pops the last item off the Vector.""" |
| 152 | return self._pop(self._to_transaction(tr)) |
| 153 | |
| 154 | def swap(self, i1, i2, tr=None): |
| 155 | """Swap the items at positions i1 and i2.""" |
| 156 | self._swap(i1, i2, self._to_transaction(tr)) |
| 157 | |
| 158 | def get(self, index, tr=None): |
| 159 | """Get the item at the specified index.""" |
| 160 | return self._get(index, self._to_transaction(tr)) |
| 161 | |
| 162 | def get_range(self, startIndex=None, endIndex=None, step=None, tr=None): |
| 163 | """Get a range of items in the Vector, returned as a generator.""" |
| 164 | return self._get_range(startIndex, endIndex, step, self._to_transaction(tr)) |
| 165 | |
| 166 | def set(self, index, val, tr=None): |
no outgoing calls
no test coverage detected