image.vision\aoci\aoci_index.mbt
100% · 35 / 35 points · 125 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # AOCI 符号语义索引 AOCI Symbol Semantic Index - 3
/// - 4
/// 全量符号索引 + 关键词倒排表 - 5
/// 全符号索引 + 关键词倒排表 Full symbol index - 6
// AOCI 符号语义索引 — 符号索引结构 - 7
// SymbolIndex: 全量符号索引 + 关键词倒排表 - 8
- 9
///| - 10
#derive(Eq, @debug.Debug) - 11
pub(all) struct SymbolIndex { - 12
symbols : Array[SymbolCoord] - 13
keyword_map : Array[(String, Array[Int32])] - 14
} - 15
- 16
///| - 17
pub extend SymbolIndex with Eq::{not_equal, equal} - 18
- 19
///| - 20
pub extend SymbolIndex with @debug.Debug::{to_repr} - 21
- 22
///| - 23
pub fn SymbolIndex::make(symbols : Array[SymbolCoord]) -> SymbolIndex { - 24●
let keyword_map : Array[(String, Array[Int32])] = [] - 25●
for i in 0..<symbols.length() { - 26●
for kw in symbols[i].keywords { - 27●
let mut found = false - 28●
for j in 0..<keyword_map.length() { - 29●
if keyword_map[j].0 == kw { - 30●
keyword_map[j].1.push(i) - 31
found = true - 32
break - 33
} - 34
} - 35
if !found { - 36●
keyword_map.push((kw, [i])) - 37
} - 38
} - 39
} - 40
{ symbols, keyword_map, } - 41
} - 42
- 43
///| - 44
pub fn SymbolIndex::size(self : SymbolIndex) -> Int32 { - 45●
self.symbols.length() - 46
} - 47
- 48
///| - 49
pub fn SymbolIndex::get( - 50
self : SymbolIndex, - 51
index : Int32, - 52
) -> SymbolCoord raise Failure { - 53●
if index < 0 || index >= self.symbols.length() { - 54●
fail("symbol index out of bounds: \{index}") - 55
} - 56
self.symbols[index] - 57
} - 58
- 59
///| - 60
pub fn SymbolIndex::find_by_name( - 61
self : SymbolIndex, - 62
name : String, - 63
) -> Array[SymbolCoord] { - 64●
let result : Array[SymbolCoord] = [] - 65
for sym in self.symbols { - 66●
if sym.name == name { - 67●
result.push(sym) - 68
} - 69
} - 70
result - 71
} - 72
- 73
///| - 74
pub fn SymbolIndex::find_by_package( - 75
self : SymbolIndex, - 76
pkg : String, - 77
) -> Array[SymbolCoord] { - 78●
let result : Array[SymbolCoord] = [] - 79
for sym in self.symbols { - 80●
if sym.pkg == pkg { - 81●
result.push(sym) - 82
} - 83
} - 84
result - 85
} - 86
- 87
///| - 88
pub fn SymbolIndex::find_by_keyword( - 89
self : SymbolIndex, - 90
keyword : String, - 91
) -> Array[SymbolCoord] { - 92●
for entry in self.keyword_map { - 93●
if entry.0 == keyword { - 94●
let result : Array[SymbolCoord] = [] - 95
for idx in entry.1 { - 96●
result.push(self.symbols[idx]) - 97
} - 98
return result - 99
} - 100
} - 101
[] - 102
} - 103
- 104
///| - 105
pub fn SymbolIndex::find_by_kind( - 106
self : SymbolIndex, - 107
kind : SymbolKind, - 108
) -> Array[SymbolCoord] { - 109●
let result : Array[SymbolCoord] = [] - 110
for sym in self.symbols { - 111●
if sym.kind == kind { - 112●
result.push(sym) - 113
} - 114
} - 115
result - 116
} - 117
- 118
///| - 119
pub fn SymbolIndex::total_tokens(self : SymbolIndex) -> Int32 { - 120●
let mut sum = 0 - 121
for sym in self.symbols { - 122●
sum = sum + sym.estimated_tokens() - 123
} - 124
sum - 125
}