January 2020
Intermediate to advanced
640 pages
16h 56m
English
To obtain an iterator for the graph links or edges, users need to invoke the Links or Edges methods. Let's take a look at how the Links method is implemented:
func (s *InMemoryGraph) Links(fromID, toID uuid.UUID, retrievedBefore time.Time) (graph.LinkIterator, error) { from, to := fromID.String(), toID.String() s.mu.RLock() var list []*graph.Link for linkID, link := range s.links { if id := linkID.String(); id >= from && id < to && link.RetrievedAt.Before(retrievedBefore) { list = append(list, link) } } s.mu.RUnlock() return &linkIterator{s: s, links: list}, nil }
In the preceding implementation, we obtain a read lock and then proceed to iterate all the links in the graph, searching for the ones that belong to the