@@ -4,6 +4,34 @@ use std::collections::HashMap;
44
55use crate :: model:: { Attribute , SeriesId , SeriesSpec } ;
66
7+ /// Trait for looking up series specs by ID.
8+ /// This allows both ForwardIndex and view types to be used interchangeably.
9+ pub ( crate ) trait ForwardIndexLookup {
10+ /// Get the series spec for a given series ID.
11+ /// Returns None if the series is not found.
12+ fn get_spec ( & self , series_id : & SeriesId ) -> Option < SeriesSpec > ;
13+ }
14+
15+ impl < T : ForwardIndexLookup + ?Sized > ForwardIndexLookup for Box < T > {
16+ fn get_spec ( & self , series_id : & SeriesId ) -> Option < SeriesSpec > {
17+ ( * * self ) . get_spec ( series_id)
18+ }
19+ }
20+
21+ /// Trait for querying inverted index data.
22+ /// This allows both InvertedIndex and view types to be used interchangeably.
23+ pub ( crate ) trait InvertedIndexLookup {
24+ /// Intersect posting lists for the given terms.
25+ /// Returns series IDs that match ALL terms.
26+ fn intersect ( & self , terms : Vec < Attribute > ) -> RoaringBitmap ;
27+ }
28+
29+ impl < T : InvertedIndexLookup + ?Sized > InvertedIndexLookup for Box < T > {
30+ fn intersect ( & self , terms : Vec < Attribute > ) -> RoaringBitmap {
31+ ( * * self ) . intersect ( terms)
32+ }
33+ }
34+
735#[ derive( Debug , Clone , Default ) ]
836pub ( crate ) struct ForwardIndex {
937 pub ( crate ) series : DashMap < SeriesId , SeriesSpec > ,
@@ -19,14 +47,20 @@ impl ForwardIndex {
1947 }
2048}
2149
50+ impl ForwardIndexLookup for ForwardIndex {
51+ fn get_spec ( & self , series_id : & SeriesId ) -> Option < SeriesSpec > {
52+ self . series . get ( series_id) . map ( |r| r. value ( ) . clone ( ) )
53+ }
54+ }
55+
2256#[ derive( Debug , Clone , Default ) ]
2357pub ( crate ) struct InvertedIndex {
2458 /// Maps Attribute (key, value) to the list of series_id values containing it.
2559 pub ( crate ) postings : DashMap < Attribute , RoaringBitmap > ,
2660}
2761
28- impl InvertedIndex {
29- pub ( crate ) fn intersect ( & self , terms : Vec < Attribute > ) -> RoaringBitmap {
62+ impl InvertedIndexLookup for InvertedIndex {
63+ fn intersect ( & self , terms : Vec < Attribute > ) -> RoaringBitmap {
3064 if terms. is_empty ( ) {
3165 return RoaringBitmap :: new ( ) ;
3266 }
@@ -51,7 +85,9 @@ impl InvertedIndex {
5185
5286 result
5387 }
88+ }
5489
90+ impl InvertedIndex {
5591 pub ( crate ) fn union ( & self , terms : Vec < Attribute > ) -> RoaringBitmap {
5692 if terms. is_empty ( ) {
5793 return RoaringBitmap :: new ( ) ;
0 commit comments