Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions docs/src/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ A type implementing the `Network` interface must implement the following methods

The following methods have a default implementation or their implementation is optional.

| Method | When should this method be defined? | Default definition | Brief description |
| :------------------ | :--------------------------------------------------- | :-------------------- | :----------------------------------------------------- |
| `vertex_type(g)` | If your vertex type is type-stable | `Any` | Returns the type used for representing a vertex |
| `edge_type(g)` | If your edge type is type-stable | `Any` | Returns the type used for representing an edge |
| `hasvertex(g, v)` | If there is a more performant way | `v in vertices(g)` | Returns `true` if vertex `v` is present in network `g` |
| `hasedge(g, e)` | If there is a more performant way | `e in edges(g)` | Returns `true` if edge `e` is present in network `e` |
| `nvertices(g)` | If there is a more performant way | `length(vertices(g))` | Returns the number of vertices present in the network |
| `nedges(g)` | If there is a more performant way | `length(edges(g))` | Returns the number of edges present in the network |
| `vertex_at(g, tag)` | If your type has some other way to refer to a vertex | _(undefined)_ | Returns the vertex related to `tag` |
| `edge_at(g, tag)` | If your type has some other way to refer to an edge | _(undefined)_ | Returns the edge related to `tag` |
| Method | When should this method be defined? | Default definition | Brief description |
| :---------------- | :---------------------------------- | :-------------------- | :----------------------------------------------------- |
| `vertex_type(g)` | If your vertex type is type-stable | `Any` | Returns the type used for representing a vertex |
| `edge_type(g)` | If your edge type is type-stable | `Any` | Returns the type used for representing an edge |
| `hasvertex(g, v)` | If there is a more performant way | `v in vertices(g)` | Returns `true` if vertex `v` is present in network `g` |
| `hasedge(g, e)` | If there is a more performant way | `e in edges(g)` | Returns `true` if edge `e` is present in network `e` |
| `nvertices(g)` | If there is a more performant way | `length(vertices(g))` | Returns the number of vertices present in the network |
| `nedges(g)` | If there is a more performant way | `length(edges(g))` | Returns the number of edges present in the network |

### Mutating methods

Expand All @@ -56,6 +54,11 @@ The [`EdgePersistence`](@ref Networks.EdgePersistence) trait defines the behavio

WIP

| Required method | Description |
| :------------------ | :---------------------------------- |
| `vertex_at(g, tag)` | Returns the vertex related to `tag` |
| `edge_at(g, tag)` | Returns the edge related to `tag` |

## Attributeable

WIP
15 changes: 0 additions & 15 deletions src/Interfaces/Network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ Returns the edges connected to vertex `v` in `graph`.
"""
function vertex_incidents end

function vertex_at end
function edge_at end

:(Base.copy)

# query methods with default implementation
"""
vertex_type(graph)
Expand Down Expand Up @@ -253,16 +248,6 @@ function nedges(graph, ::DontDelegate)
return length(edges(graph))
end

## `vertex_at`
vertex_at(graph, tag) = vertex_at(graph, tag, DelegatorTrait(Network(), graph))
vertex_at(graph, tag, ::DelegateToField) = vertex_at(delegator(Network(), graph), tag)
vertex_at(graph, tag, ::DontDelegate) = throw(MethodError(vertex_at, (graph, tag)))

## `edge_at`
edge_at(graph, tag) = edge_at(graph, tag, DelegatorTrait(Network(), graph))
edge_at(graph, tag, ::DelegateToField) = edge_at(delegator(Network(), graph), tag)
edge_at(graph, tag, ::DontDelegate) = throw(MethodError(edge_at, (graph, tag)))

## `edges_set_strand`
edges_set_strand(graph) = edges_set_strand(graph, DelegatorTrait(Network(), graph))
edges_set_strand(graph, ::DelegateToField) = edges_set_strand(delegator(Network(), graph))
Expand Down
15 changes: 14 additions & 1 deletion src/Interfaces/Taggable.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct Taggable <: Interface end
struct Taggable{T} <: Interface end

# traits
# WARN experimental
Expand All @@ -24,6 +24,9 @@ function untag! end
function replace_tag! end

# query methods
function vertex_at end
function edge_at end

function vertex_tags end
function edge_tags end

Expand Down Expand Up @@ -56,6 +59,16 @@ hastag(graph, tag, ::EdgeTagKind) = has_edge_tag(graph, tag)
tag_at(graph, v::AbstractVertex) = tag_at_vertex(graph, v)
tag_at(graph, e::AbstractEdge) = tag_at_edge(graph, e)

## `vertex_at`
vertex_at(graph, tag) = vertex_at(graph, tag, DelegatorTrait(Network(), graph))
vertex_at(graph, tag, ::DelegateToField) = vertex_at(delegator(Network(), graph), tag)
vertex_at(graph, tag, ::DontDelegate) = throw(MethodError(vertex_at, (graph, tag)))

## `edge_at`
edge_at(graph, tag) = edge_at(graph, tag, DelegatorTrait(Network(), graph))
edge_at(graph, tag, ::DelegateToField) = edge_at(delegator(Network(), graph), tag)
edge_at(graph, tag, ::DontDelegate) = throw(MethodError(edge_at, (graph, tag)))

## `replace_tag!`
replace_tag!(graph, old, new) = replace_tag!(graph, old, new, TagKind(old), TagKind(new))
replace_tag!(graph, old, new, ::VertexTagKind, ::VertexTagKind) = replace_vertex_tag!(graph, old, new)
Expand Down
Loading