From bc413a1749e66de73e79ba026def25136c145cec Mon Sep 17 00:00:00 2001 From: Calvin Lobo Date: Mon, 19 Aug 2024 11:46:00 -0400 Subject: [PATCH] Added GetAllReferences() and GetAllMappedReferences() methods to Rolodex --- index/rolodex.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index/rolodex.go b/index/rolodex.go index 3a3450b1..83568f6a 100644 --- a/index/rolodex.go +++ b/index/rolodex.go @@ -10,6 +10,7 @@ import ( "io" "io/fs" "log/slog" + "maps" "math" "os" "path/filepath" @@ -425,6 +426,26 @@ func (r *Rolodex) BuildIndexes() { r.manualBuilt = true } +// GetAllReferences returns all references found in the root and all other indices +func (r *Rolodex) GetAllReferences() map[string]*Reference { + allRefs := make(map[string]*Reference) + for _, idx := range append(r.GetIndexes(), r.GetRootIndex()) { + refs := idx.GetAllReferences() + maps.Copy(allRefs, refs) + } + return allRefs +} + +// GetAllMappedReferences returns all mapped references found in the root and all other indices +func (r *Rolodex) GetAllMappedReferences() map[string]*Reference { + mappedRefs := make(map[string]*Reference) + for _, idx := range append(r.GetIndexes(), r.GetRootIndex()) { + refs := idx.GetMappedReferences() + maps.Copy(mappedRefs, refs) + } + return mappedRefs +} + // Open opens a file in the rolodex, and returns a RolodexFile. func (r *Rolodex) Open(location string) (RolodexFile, error) {