This may be breaking if users check err == instead of errors.Is for specific errors (such as err == ErrVertexNotFound and not errors.Is(err, ErrVertexNotFound). Depending on versioning strategy and definition of a breaking change, this may warrant a new major version.
This change also fixes a few issues I found in memoryStore:
AddEdge did not conform to the Store interface: "If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex"
UpdateEdge had a data race in which the edge could have changed between the s.Edge call and the setting of the edges due to not holding onto the lock.
CreatesCycle was not read locking before accessing s.inEdges
To let the store handle error cases when it is part of its interface definition, undirected and directed:
AddEdge don't check the vertices for existence
RemoveEdge don't check edge existence
And a few minor changes I made while I was there:
Use ListEdges instead of AdjacencyMap for Size, saves some allocations and another pass through the edges to create the map
undirected copy directed's createsCycle method to delegate to the store's version for a more performant implementation
Adds the following error structs:
VertexAlreadyExistsError[K, T]
VertexNotFoundError[K]
EdgeAlreadyExistsError[K]
EdgeNotFoundError[K]
VertexHasEdges[K]
EdgeCausesCycleError[K]
This may be breaking if users check
err ==
instead oferrors.Is
for specific errors (such aserr == ErrVertexNotFound
and noterrors.Is(err, ErrVertexNotFound)
. Depending on versioning strategy and definition of a breaking change, this may warrant a new major version.This change also fixes a few issues I found in memoryStore:
AddEdge
did not conform to theStore
interface: "If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex"UpdateEdge
had a data race in which the edge could have changed between thes.Edge
call and the setting of the edges due to not holding onto the lock.CreatesCycle
was not read locking before accessings.inEdges
To let the store handle error cases when it is part of its interface definition,
undirected
anddirected
:AddEdge
don't check the vertices for existenceRemoveEdge
don't check edge existenceAnd a few minor changes I made while I was there:
ListEdges
instead ofAdjacencyMap
forSize
, saves some allocations and another pass through the edges to create the mapundirected
copydirected
'screatesCycle
method to delegate to the store's version for a more performant implementation