dominikbraun / graph

A library for creating generic graph data structures and modifying, analyzing, and visualizing them.
https://graph.dominikbraun.io
Apache License 2.0
1.77k stars 95 forks source link

Expose MemoryStore #164

Open davidovich opened 7 months ago

davidovich commented 7 months ago

At $WORK, we implement our own Store interface for reading existing db entities into a graph. This store only implements Read related interface functions of the Store interface and works nicely.

We now would like to implement a partial Store with only Write related Store interface and reuse existing implementation from the existing default memoryStore. For example, I would like to be able to write:

Note that generics were omitted in the following to lighten the code.

// myGraphWriter implements the graph.Store interface because it embeds a MemoryStore
type myGraphWriter struct {
    graph.MemoryStore // this isn't possible because the memoryStore is private
}

// We selectively (or partially) implement writer related functions
func (g *myGraphWriter) AddVertex(hash K, value T, properties VertexProperties) error {
    v := g.MemoryStore.AddVertex() // memory dispatch
    // do proprietary db stuff here
}

Because the current memoryStore is private, we would need to reimplement our memory store just to override write-related functions. Embedding nicely fixes that - but memoryStore should be exposed.

I propose we make the memoryStore public: memoryStore -> MemoryStore. Fields of the MemoryStore may stay private.

dominikbraun commented 4 months ago

Sorry for the late response, I had a busy time at work and I'm back now. This sounds reasonable, going to review the PR!