Added GetAllReferences() and GetAllMappedReferences() methods to Rolodex

This commit is contained in:
Calvin Lobo
2024-08-19 11:46:00 -04:00
committed by quobix
parent 9ab482ac9b
commit 546778c93e

View File

@@ -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) {