ssruntime/eval/
ssab_lookup.rs1use ssab::ssab::ss::format::{Cell, CellMap, Effect};
2
3fn find_by_name_hash<'a, T>(items: &flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<T>>, name_hash: u32, cmp: impl Fn(&T, u32) -> core::cmp::Ordering) -> Option<T>
4where
5 T: flatbuffers::Follow<'a, Inner = T> + 'a,
6{
7 let mut low = 0usize;
8 let mut high = items.len();
9 while low < high {
10 let mid = (low + high) / 2;
11 let item = items.get(mid);
12 match cmp(&item, name_hash) {
13 core::cmp::Ordering::Equal => return Some(item),
14 core::cmp::Ordering::Less => low = mid + 1,
15 core::cmp::Ordering::Greater => high = mid,
16 }
17 }
18 None
19}
20
21#[inline]
22pub fn find_cellmap<'a>(cellmaps: &flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CellMap<'a>>>, name_hash: u32) -> Option<CellMap<'a>> {
23 find_by_name_hash(cellmaps, name_hash, |c, v| c.key_compare_with_value(v))
24}
25
26#[inline]
27pub fn find_cell<'a>(cells: &flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Cell<'a>>>, name_hash: u32) -> Option<Cell<'a>> {
28 find_by_name_hash(cells, name_hash, |c, v| c.key_compare_with_value(v))
29}
30
31#[inline]
32pub fn find_effect<'a>(effects: &flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Effect<'a>>>, name_hash: u32) -> Option<Effect<'a>> {
33 find_by_name_hash(effects, name_hash, |e, v| e.key_compare_with_value(v))
34}