@@ -8,7 +8,7 @@ use bitvec::vec::BitVec;
88use std:: collections:: { HashMap , HashSet } ;
99
1010use crate :: {
11- circuit:: { Identifier , Instantiable } ,
11+ circuit:: Instantiable ,
1212 netlist:: { NetRef , Netlist } ,
1313} ;
1414
@@ -92,10 +92,10 @@ pub struct AttributeFilter<'a, I: Instantiable> {
9292 _netlist : & ' a Netlist < I > ,
9393 // The keys to filter by
9494 keys : Vec < AttributeKey > ,
95- // The set of identifiers that have this attribute
96- set : HashSet < Identifier > ,
9795 /// The mapping of netrefs that have this attribute
98- map : HashMap < Identifier , NetRef < I > > ,
96+ map : HashMap < AttributeKey , HashSet < NetRef < I > > > ,
97+ /// Contains a dedup collection of all filtered nodes
98+ full_set : HashSet < NetRef < I > > ,
9999}
100100
101101impl < ' a , I > AttributeFilter < ' a , I >
@@ -104,32 +104,29 @@ where
104104{
105105 /// Create a new filter for the netlist
106106 fn new ( netlist : & ' a Netlist < I > , keys : Vec < AttributeKey > ) -> Self {
107- let mut set = HashSet :: new ( ) ;
108107 let mut map = HashMap :: new ( ) ;
108+ let mut full_set = HashSet :: new ( ) ;
109109 for nr in netlist. objects ( ) {
110110 for attr in nr. attributes ( ) {
111111 if keys. contains ( attr. key ( ) ) {
112- if let Some ( inst) = nr. get_instance_name ( ) {
113- set. insert ( inst. clone ( ) ) ;
114- map. insert ( inst. clone ( ) , nr. clone ( ) ) ;
115- }
116- for net in nr. nets ( ) {
117- set. insert ( net. get_identifier ( ) . clone ( ) ) ;
118- }
112+ map. entry ( attr. key ( ) . clone ( ) )
113+ . or_insert_with ( HashSet :: new)
114+ . insert ( nr. clone ( ) ) ;
115+ full_set. insert ( nr. clone ( ) ) ;
119116 }
120117 }
121118 }
122119 Self {
123120 _netlist : netlist,
124121 keys,
125- set,
126122 map,
123+ full_set,
127124 }
128125 }
129126
130- /// Check if an identifier has one of the attributes
131- pub fn has ( & self , id : & Identifier ) -> bool {
132- self . set . contains ( id )
127+ /// Check if an node matches any of the filter keys
128+ pub fn has ( & self , n : & NetRef < I > ) -> bool {
129+ self . map . values ( ) . any ( |s| s . contains ( n ) )
133130 }
134131
135132 /// Return a slice to the keys that were used for filtering
@@ -144,10 +141,10 @@ where
144141{
145142 type Item = NetRef < I > ;
146143
147- type IntoIter = std:: collections:: hash_map :: IntoValues < Identifier , NetRef < I > > ;
144+ type IntoIter = std:: collections:: hash_set :: IntoIter < NetRef < I > > ;
148145
149146 fn into_iter ( self ) -> Self :: IntoIter {
150- self . map . into_values ( )
147+ self . full_set . into_iter ( )
151148 }
152149}
153150
0 commit comments