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

Removing stale edges

The last bit of functionality that we need to explore is the RemoveStaleEdges method. The caller invokes it with the ID of a link (the origin) and an updatedBefore value:

func (s *InMemoryGraph) RemoveStaleEdges(fromID uuid.UUID, updatedBefore time.Time) error {
    s.mu.Lock()
    defer s.mu.Unlock()

    var newEdgeList edgeList
    for _, edgeID := range s.linkEdgeMap[fromID] {
        edge := s.edges[edgeID]
        if edge.UpdatedAt.Before(updatedBefore) {
            delete(s.edges, edgeID)
            continue
        }
        newEdgeList = append(newEdgeList, edgeID)
    }
    s.linkEdgeMap[fromID] = newEdgeList
    return nil
}

As with other operations that mutate the graph's contents, we need to acquire a write lock. Then, we iterate the list of edges that originate from the specified source ...

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