Comments (7)
Draft for new Graph
interface (updated)
type Graph[K comparable, T any] interface {
Traits() *Traits
AddVertex(value T) error
Vertex(hash K) (T, error)
AddEdge(source, target K, options ...func(*EdgeProperties)) error
Edge(source, target T) (Edge[T], error)
AdjacencyMap() (map[K]map[K]Edge[K], error)
Predecessors(vertex K) (map[K]Edge[K], error)
}
All the DFS, BFS, Shortest Path, and SCC methods are removed. The Graph
interface only provides "CRUD" operations for the graphs and its vertices and edges.
from graph.
That sounds like a really nice separation!!
Can I take this opportunity to raise a couple of small points that seemed a bit weird when I first saw the graph api?
- Are both the
X()
and theXByHash()
methods really needed? Is it useful enough to the developer that warrants doubling the number of methods on the graph interface?
This is not a big deal by any means, mostly bringing this up out of curiosity, the love of bikeshedding, and an interest in clean interfaces :D
- Any chance we could prefix all methods with a verb and not just some? It's a weird experience when you first see a method
Vertex()
and are not sure if it gets or puts.
In the new API there are also some discrepancies in the naming.
Traits()
getsEdge()
putsVertex()
putsDegree()
gets- etc
- Could all methods return an error? It's a bit weird that some return just a value, some also return bool, and some also return an error. - This would also be really useful for features such as adding more persistence layers etc.
ie. Maybe something like this?
type Graph[K comparable, T any] interface {
GetTraits() Traits
AddVertex(value T) error
GetVertex(hash K) (T, error)
AddEdge(sourceHash, targetHash K, options ...func(*EdgeProperties)) error
GetEdge(sourceHash, targetHash K) (Edge[T], error)
GetDegree(vertexHash K) (int, error)
GetAdjacencyMap() (map[K]map[K]Edge[K], error)
}
Looking forward to whatever the new API looks like :D
from graph.
Thanks for your thoughts!
-
I'm having a hard time deciding for the user when they want to work with a hash value and when they want to work with the vertex value, hence I simply created a method for either way. With #24, we could make it configurable whether the user wants to work with hashes or vertices and cut those duplicated methods. If the user opts in to using hash values, the passed arguments to methods like
GetEgde
would be interpreted as hashes, not vertices. -
Yes. The naming of
Vertex
andEdge
was supposed to make the API more declarative and less imperative, but I see that this mixed form might be a bit confusing. -
I think with the new
Store
interfaces, all of these methods will need to return an error anyway.
from graph.
@geoah I've updated the draft for the new Graph
interface to the extent that all methods return an error and "adding" methods have an Add
prefix.
As to the Get
methods, while it makes sense to prefix all the methods with a verb, there is also the convention of Getters without the Get
prefix. What would you prefer here?
from graph.
@dominikbraun prefixing the Add
ones and keeping the getters without a verb sounds like a good solution!
Doesn't look half bad.
type Graph[K comparable, T any] interface {
Traits() Traits
AddVertex(value T) error
Vertex(hash K) (T, error)
AddEdge(sourceHash, targetHash K, options ...func(*EdgeProperties)) error
Edge(sourceHash, targetHash K) (Edge[T], error)
Degree(vertexHash K) (int, error)
AdjacencyMap() (map[K]map[K]Edge[K], error)
}```
from graph.
Another possibility would be to only prefix non-trivial "getters" with Get
, which are getters that involve some computation at runtime or return an error, e.g. GetEdge
; and omit the prefix for "real" getters such as Degree
. We'll see.
from graph.
Alright, I've updated the new Graph
interface draft and opened a corresponding PR: #27
from graph.
Related Issues (20)
- Return a slice of all vertices in the graph. HOT 1
- RemoveVertex from graph HOT 2
- go1.20.5 type problem HOT 4
- GitHub Actions CI could be optimized HOT 1
- Shortest Path Doesn't Support Negative Edge Weights Properly HOT 6
- Query edges from/to given vertex HOT 4
- Vertex Attributes And Edge Attributes auto add double quote
- BFSWithDepth not calculating depth correctly HOT 3
- DAG Graph Pagination
- No way to list vertices? HOT 1
- How to split graph into disconnected subgraphs HOT 4
- Expose MemoryStore HOT 1
- can i find the leader/source vertex of a directed acyclic graph ? HOT 5
- multigraph support HOT 4
- Topological sort has a significant performance penalty HOT 1
- Feature Request: Add method for updating Vertex property HOT 1
- Feature: Add method for querying toVertex/fromVertex and steps HOT 1
- can value of vertexAttribute be of type 'any' ?
- guidance on marshaling/unmarshaling
- VertexAttributes func caching last values
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graph.