MCPcopy Index your code
hub / github.com/coder/coder / Add

Method Add

agent/filefinder/delta.go:52–75  ·  view source on GitHub ↗

Add inserts a path into the index, tombstoning any previous entry.

(path string, flags uint16)

Source from the content-addressed store, hash-verified

50
51// Add inserts a path into the index, tombstoning any previous entry.
52func (idx *Index) Add(path string, flags uint16) uint32 {
53 norm := string(normalizePathBytes([]byte(path)))
54 if oldID, ok := idx.byPath[norm]; ok {
55 idx.deleted[oldID] = true
56 }
57 id := uint32(len(idx.docs)) //nolint:gosec // Index will never exceed 2^32 docs.
58 baseOff, baseLen := extractBasename([]byte(norm))
59 idx.docs = append(idx.docs, doc{
60 path: norm, baseOff: baseOff, baseLen: baseLen,
61 depth: strings.Count(norm, "/"), flags: flags,
62 })
63 idx.byPath[norm] = id
64 for _, g := range extractTrigrams([]byte(norm)) {
65 idx.byGram[g] = append(idx.byGram[g], id)
66 }
67 if baseLen > 0 {
68 basename := []byte(norm[baseOff : baseOff+baseLen])
69 p1 := prefix1(basename)
70 idx.byPrefix1[p1] = append(idx.byPrefix1[p1], id)
71 p2 := prefix2(basename)
72 idx.byPrefix2[p2] = append(idx.byPrefix2[p2], id)
73 }
74 return id
75}
76
77// Remove marks the entry for path as deleted.
78func (idx *Index) Remove(path string) bool {

Callers 11

walkRootFunction · 0.95
MakeTestSnapshotFunction · 0.95
TestIndex_AddAndLenFunction · 0.95
TestIndex_HasFunction · 0.95
TestIndex_RemoveFunction · 0.95
TestIndex_AddOverwriteFunction · 0.95
TestIndex_SnapshotFunction · 0.95
TestIndex_TrigramIndexFunction · 0.95
TestIndex_PrefixIndexFunction · 0.95

Calls 6

normalizePathBytesFunction · 0.85
extractBasenameFunction · 0.85
extractTrigramsFunction · 0.85
prefix1Function · 0.85
prefix2Function · 0.85
CountMethod · 0.80

Tested by 10

MakeTestSnapshotFunction · 0.76
TestIndex_AddAndLenFunction · 0.76
TestIndex_HasFunction · 0.76
TestIndex_RemoveFunction · 0.76
TestIndex_AddOverwriteFunction · 0.76
TestIndex_SnapshotFunction · 0.76
TestIndex_TrigramIndexFunction · 0.76
TestIndex_PrefixIndexFunction · 0.76