Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Implementing an in-memory graph store

The in-memory graph implementation will serve as a gentle introduction to writing a complete graph store implementation. By virtue of maintaining the graph in memory, this implementation is simple, self-contained, and safe for concurrent access. This makes it an ideal candidate for writing unit tests that require access to the link graph component.

Let's take a look at its implementation, starting with the definition of the InMemoryGraph type:

type edgeList []uuid.UUID

type InMemoryGraph struct {
    mu sync.RWMutex

    links map[uuid.UUID]*graph.Link
    edges map[uuid.UUID]*graph.Edge

    linkURLIndex map[string]*graph.Link
    linkEdgeMap  map[uuid.UUID]edgeList
}

The InMemoryGraph struct defines two maps (links and

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content