Indexing
Indexing and topology helpers from annnet.core._Index.
annnet.core._Index.IndexManager
Namespace for index operations. Provides clean API over existing dicts.
Functions
entity_to_row(entity_id)
Map an entity ID to its matrix row index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Row index for the entity. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the entity is not found. |
row_to_entity(row)
Map a matrix row index to its entity ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
int
|
Row index. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Entity identifier. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the row index is not found. |
entities_to_rows(entity_ids)
Batch convert entity IDs to row indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_ids
|
Iterable[str]
|
Entity identifiers. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
|
rows_to_entities(rows)
Batch convert row indices to entity IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Iterable[int]
|
Row indices. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
edge_to_col(edge_id)
Map an edge ID to its matrix column index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Column index for the edge. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the edge is not found. |
col_to_edge(col)
Map a matrix column index to its edge ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col
|
int
|
Column index. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Edge identifier. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the column index is not found. |
edges_to_cols(edge_ids)
Batch convert edge IDs to column indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_ids
|
Iterable[str]
|
Edge identifiers. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
|
cols_to_edges(cols)
Batch convert column indices to edge IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cols
|
Iterable[int]
|
Column indices. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
entity_type(entity_id)
Get the entity type for an ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If the entity is not found. |
is_vertex(entity_id)
Check whether an entity ID refers to a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
is_edge_entity(entity_id)
Check whether an entity ID refers to an edge-entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_entity(entity_id)
Check if an ID exists as any entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Entity identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_vertex(vertex_id)
Check if an ID exists and is a vertex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_id
|
str
|
Vertex identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
has_edge_id(edge_id)
Check if an edge ID exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
edge_count()
Return the number of edges in the graph.
Returns:
| Type | Description |
|---|---|
int
|
|
entity_count()
Return the number of entities (vertices + edge-entities).
Returns:
| Type | Description |
|---|---|
int
|
|
vertex_count()
Return the number of true vertices (excludes edge-entities).
Returns:
| Type | Description |
|---|---|
int
|
|
stats()
Return index statistics for entities and edges.
Returns:
| Type | Description |
|---|---|
dict
|
|