Welcome to structs’s documentation!

Release v0.0.1.

Python Data Structures for Humans

Generic, pure Python implementations of some more common types of data structures.

User Guide:

structs package

structs.arrays module

structs.arrays.prev(iterable)[source]

Iterate in reverse over an iterable type supporting the __prev__ API

class structs.arrays.BaseList(*args, **kwargs)[source]

Bases: list

Custom list subclass with some additional iteration functionality

next()

Handle next iteration functionality

prev()

Add basic implementation of the prev API

class structs.arrays.BitArray(iterable=())[source]

Bases: list

A bit array (also known as bitmap, bitset, bit string, or bit vector) is an array data structure that compactly stores bits. It can be used to implement a simple set data structure. A bit array is effective at exploiting bit-level parallelism in hardware to perform operations quickly.

append(p_object)[source]

Append the logical bitwise representation of p_object

extend(iterable)[source]

Append the logical bitwise representation of the objects in iterable

insert(index, p_object)[source]

Append the logical bitwise representation of p_object to index

class structs.arrays.SortedList(iterable=(), key=None, reverse=False)[source]

Bases: list

A list implementation that always maintains a sorted order

append(p_object)[source]

Add p_object into ordered place in the list

extend(iterable)[source]

Append each item in iterable into it’s sorted location in the list

insert(p_object, *args)[source]

Insert p_object at it’s calculated index

class structs.arrays.CircularArray(*args, **kwargs)[source]

Bases: structs.arrays.BaseList

A list subclass that will continually iterate until explicitly broken out of. ie, you’re probably going to want a return or break in a loop over a CircularArray

structs.maps module

class structs.maps.Dict[source]

Bases: dict

Overriden dict type with iadd functionality which will allow you to append two dictionaries together. ie:

>>> d = Dict(a=1, b=2)
>>> d += {'c': 3, 'd': 4}
>>> d

... {‘a’: 1, ‘b’: 2, ‘c’: 3, ‘d’: 4}

class structs.maps.BiDirectionalMap(iterable=None, **kwargs)[source]

Bases: structs.maps.Dict

a bidirectional map, or hash bag, is an associative data structure in which the (key, value) pairs form a one-to-one correspondence. Thus the binary relation is functional in each direction: value can also act as a key to key. A pair (a, b) thus provides a unique coupling between a and b so that b can be found when a is used as a key and a can be found when b is used as a key.

get(k, d=None)[source]

Return self[k] if k is in this bidirectionaldict, otherwise return d

Parameters:
  • k – A key to return from this bidirectionaldict
  • d – The default value to return if k is not in this bidirectionaldict
Returns:

The value mapped to by k or d if k is not in this bidirectionaldict

items()[source]

Return a 2-tuple of the (key, value) pairs in this BiDirectionalDict

keys()[source]

Return a generator of the keys in this BiDirectionalDict

values()[source]

Return a generator of the values in this BiDirectionalDict

class structs.maps.MultiMap[source]

Bases: structs.maps.Dict

A MultiMap is a generalization of a dict type in which more than one value may be associated with and returned for a given key

setdefault(k, d=None)[source]

If k is not contained in this MultiMap then store the value d in it.

Parameters:
  • k – The key to set the value for
  • d – The default value to assign to key k
Returns:

The value stored at key k

update(other=None, **kwargs)[source]

Update this MultiMap with either the

Parameters:
  • other – Another dict to merge into this MultiMap or an iterable of (key, value) 2-tuples
  • kwargs – Arbitrary keyword args to merge into this MultiMap

Indices and tables