kinbaku.Graph.__init__¶
- Graph.__init__(filename, hash_func=None, max_str_len=15, max_key_len=15, int_format='l', char_format='h', bool_format='?', hash_format='I', cache_len=1000000, table_increment=100000, preload=False, node_class=None, edge_class=None, flag='w')[source]¶
Initialize a directed graph. A file is automatically created if the path provided by the filename argument does not exist.
- Parameters
filename (str) – path to database. File created if it does not exist
hash_func (function, optional) – hashing function. None means that Google’s CityHash will be used. Defaults to None.
max_str_len (int, optional) – max length of a string field. Defaults to 15.
max_key_len (int, optional) – max length of node keys. Defaults to 15.
int_format (str, optional) – format for integers as described in struct package. Defaults to “l”.
char_format (str, optional) – format for characters. Defaults to “h”.
bool_format (str, optional) – format for booleans. Defaults to “?”.
hash_format (str, optional) – format for containing hashes. Defaults to “I”.
cache_len (int, optional) – maximum size of the dictionary. Defaults to 10000000.
table_increment (int, optional) – [description]. Defaults to 100000.
preload (bool, optional) – if True, all nodes attributes are loaded on initialization. Defaults to False.
node_class (dataclass, optional) – the dataclass that defines custom node attributes. Defaults to None.
edge_class (dataclass, optional) – the dataclass that defines custom edge attributes. Defaults to None.
flag (str, optional) – “w” for reading and writing, “r” for reading only, “n” for new (overwrite). Defaults to “w”.
Examples
>>> G = kn.Graph("test.db") >>> G = kn.Graph("test.db", flag="r") >>> G = kn.Graph("test.db", hash_func=lambda x: math.abs(hash(x)))