python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Module datatypes :: Class UniqueIdGenerator
[hide private]

Class UniqueIdGenerator

source code

object --+
         |
        UniqueIdGenerator

A dictionary-like class that can be used to assign unique IDs to names (say, vertex names).

Usage:

>>> gen = UniqueIdGenerator()
>>> gen["A"]
0
>>> gen["B"]
1
>>> gen["C"]
2
>>> gen["A"]      # Retrieving already existing ID
0
>>> gen.add("D")  # Synonym of gen["D"]
3
>>> len(gen)      # Number of already used IDs
4
>>> "C" in gen
True
>>> "E" in gen
False
Instance Methods [hide private]
 
__init__(self, id_generator=None, initial=None)
Creates a new unique ID generator.
source code
 
__contains__(self, item)
Checks whether `item` already has an ID or not.
source code
 
__getitem__(self, item)
Retrieves the ID corresponding to `item`.
source code
 
__setitem__(self, item, value)
Overrides the ID for `item`.
source code
 
__len__(self)
"Returns the number of items
source code
 
reverse_dict(self)
Returns the reverse mapping, i.e., the one that maps from generated IDs to their corresponding objects
source code
 
values(self)
Returns the values stored so far.
source code
 
add(self, item)
Retrieves the ID corresponding to `item`.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, id_generator=None, initial=None)
(Constructor)

source code 

Creates a new unique ID generator. `id_generator` specifies how do we assign new IDs to elements that do not have an ID yet. If it is `None`, elements will be assigned integer identifiers starting from 0. If it is an integer, elements will be assigned identifiers starting from the given integer. If it is an iterator or generator, its `next` method will be called every time a new ID is needed.

Overrides: object.__init__

__getitem__(self, item)
(Indexing operator)

source code 

Retrieves the ID corresponding to `item`. Generates a new ID for `item` if it is the first time we request an ID for it.

values(self)

source code 

Returns the values stored so far. If the generator generates items according to the standard sorting order, the values returned will be exactly in the order they were added. This holds for integer IDs for instance (but for many other ID generators as well).

add(self, item)

source code 

Retrieves the ID corresponding to `item`. Generates a new ID for `item` if it is the first time we request an ID for it.


   Home       Trees       Indices       Help