@@ -180,35 +180,14 @@ PacketTransformerManager::DecisionNode PacketTransformerManager::Flatten(
180180 return node;
181181}
182182
183- template <typename NodeOrBuilder>
184- size_t PacketTransformerManager::NodeHash::HashOfFlatSequence (
185- const NodeOrBuilder& node) {
186- size_t num_matches = 0 ;
187- size_t num_modifies = 0 ;
188- size_t hash = absl::HashOf (node.field , node.default_branch );
189- ForEachFlatEntry (
190- node,
191- [&](int match_value, uint32_t end_offset) {
192- hash = absl::HashOf (hash, match_value, end_offset);
193- ++num_matches;
194- return true ;
195- },
196- [&](int modify_value, PacketTransformerHandle branch) {
197- hash = absl::HashOf (hash, modify_value, branch);
198- ++num_modifies;
199- return true ;
200- });
201- return absl::HashOf (hash, num_matches, num_modifies);
202- }
203-
204183size_t PacketTransformerManager::NodeHash::operator ()(
205184 const DecisionNode* node) const {
206- return HashOfFlatSequence ( *node);
185+ return absl::HashOf (FlatSequenceView<DecisionNode>{ *node} );
207186}
208187
209188size_t PacketTransformerManager::NodeHash::operator ()(
210189 const DecisionNodeBuilder& builder) const {
211- return HashOfFlatSequence ( builder);
190+ return absl::HashOf (FlatSequenceView<DecisionNodeBuilder>{ builder} );
212191}
213192
214193bool PacketTransformerManager::NodeEq::operator ()(
@@ -240,10 +219,10 @@ PacketTransformerManager::ToBuilder(const DecisionNode& node) {
240219 .field = node.field ,
241220 .default_branch = node.default_branch ,
242221 };
243- for (size_t i = 0 ; i < node.matches . size (); ++i ) {
222+ for (const DecisionNode::Match& match : node.Matches () ) {
244223 absl::btree_map<int , PacketTransformerHandle>& modify_branch_by_value =
245- builder.modify_branch_by_field_match [node. matches [i]. first ];
246- for (const DecisionNode::ModifyEntry& entry : node. MatchModifies (i) ) {
224+ builder.modify_branch_by_field_match [match. value ];
225+ for (const DecisionNode::ModifyEntry& entry : match. modifies ) {
247226 modify_branch_by_value.insert (modify_branch_by_value.end (), entry);
248227 }
249228 }
@@ -950,8 +929,8 @@ PacketSetHandle PacketTransformerManager::GetAllPossibleOutputPackets(
950929 // Implements the `b_B` in the `fwd` function in section C.3 Push and Pull
951930 // in KATch: A Fast Symbolic Verifier for NetKAT.
952931 absl::flat_hash_set<int > branch_modify_values;
953- for (size_t i = 0 ; i < node.matches . size (); ++i ) {
954- for (const auto & [modify_value, branch] : node. MatchModifies (i) ) {
932+ for (const DecisionNode::Match& match : node.Matches () ) {
933+ for (const auto & [modify_value, branch] : match. modifies ) {
955934 branch_modify_values.insert (modify_value);
956935 add_to_output_by_field_value (modify_value,
957936 GetAllPossibleOutputPackets (branch));
@@ -1035,13 +1014,13 @@ PacketTransformerManager::GetAllInputPacketsThatProduceAnyOutput(
10351014 // Implements the `b_A` in the `bwd` function in section C.3 Push and Pull
10361015 // in KATch: A Fast Symbolic Verifier for NetKAT.
10371016 absl::flat_hash_map<int , PacketSetHandle> branch_by_field_value_map;
1038- for (size_t i = 0 ; i < node.matches . size (); ++i ) {
1017+ for (const DecisionNode::Match& match : node.Matches () ) {
10391018 PacketSetHandle union_of_branches;
1040- for (const auto & [modify_value, branch] : node. MatchModifies (i) ) {
1019+ for (const auto & [modify_value, branch] : match. modifies ) {
10411020 union_of_branches = packet_set_manager_.Or (
10421021 union_of_branches, GetAllInputPacketsThatProduceAnyOutput (branch));
10431022 }
1044- branch_by_field_value_map[node. matches [i]. first ] = union_of_branches;
1023+ branch_by_field_value_map[match. value ] = union_of_branches;
10451024 }
10461025
10471026 // Case 3: Input packets that do not get matched on an explicit branch, but
@@ -1110,10 +1089,9 @@ std::string PacketTransformerManager::ToString(const DecisionNode& node) const {
11101089 absl::CEscape (
11111090 packet_set_manager_.field_manager_ .GetFieldName (node.field )));
11121091
1113- for (size_t i = 0 ; i < node.matches .size (); ++i) {
1114- absl::StrAppendFormat (&result, " %s == %d:\n " , field,
1115- node.matches [i].first );
1116- pretty_print_map (field, node.MatchModifies (i));
1092+ for (const DecisionNode::Match& match : node.Matches ()) {
1093+ absl::StrAppendFormat (&result, " %s == %d:\n " , field, match.value );
1094+ pretty_print_map (field, match.modifies );
11171095 }
11181096 absl::StrAppendFormat (&result, " %s == *:\n " , field);
11191097 pretty_print_map (field, node.DefaultModifies ());
@@ -1160,10 +1138,9 @@ std::string PacketTransformerManager::ToString(
11601138 " %v:'%s'" , node.field ,
11611139 absl::CEscape (
11621140 packet_set_manager_.field_manager_ .GetFieldName (node.field )));
1163- for (size_t i = 0 ; i < node.matches .size (); ++i) {
1164- absl::StrAppendFormat (&result, " %s == %d:\n " , field,
1165- node.matches [i].first );
1166- pretty_print_map (field, node.MatchModifies (i));
1141+ for (const DecisionNode::Match& match : node.Matches ()) {
1142+ absl::StrAppendFormat (&result, " %s == %d:\n " , field, match.value );
1143+ pretty_print_map (field, match.modifies );
11671144 }
11681145 absl::StrAppendFormat (&result, " %s == *:\n " , field);
11691146 pretty_print_map (field, node.DefaultModifies ());
@@ -1216,10 +1193,9 @@ std::string PacketTransformerManager::ToDot(
12161193 packet_set_manager_.field_manager_ .GetFieldName (node.field );
12171194 absl::StrAppendFormat (&result, " %d [label=\" %s\" ]\n " ,
12181195 transformer.node_index_ , field);
1219- for (size_t i = 0 ; i < node.matches .size (); ++i) {
1220- int value = node.matches [i].first ;
1221- absl::Span<const DecisionNode::ModifyEntry> modify_map =
1222- node.MatchModifies (i);
1196+ for (const DecisionNode::Match& match : node.Matches ()) {
1197+ int value = match.value ;
1198+ absl::Span<const DecisionNode::ModifyEntry> modify_map = match.modifies ;
12231199 if (modify_map.empty ()) {
12241200 absl::StrAppendFormat (&result, " %d -> %d [label=\" %s==%s\" ]\n " ,
12251201 transformer.node_index_ , SentinelNodeIndex::kDeny ,
@@ -1309,8 +1285,8 @@ absl::Status PacketTransformerManager::CheckInternalInvariants() const {
13091285 }
13101286 return true ;
13111287 };
1312- for (size_t j = 0 ; j < node.matches . size (); ++j ) {
1313- RET_CHECK (is_strictly_sorted_by_value (node. MatchModifies (j) ))
1288+ for (const DecisionNode::Match& match : node.Matches () ) {
1289+ RET_CHECK (is_strictly_sorted_by_value (match. modifies ))
13141290 << " :\n "
13151291 << ToString (node);
13161292 }
@@ -1324,12 +1300,11 @@ absl::Status PacketTransformerManager::CheckInternalInvariants() const {
13241300 << " :\n "
13251301 << ToString (node);
13261302
1327- for (size_t j = 0 ; j < node.matches .size (); ++j) {
1328- int match_value = node.matches [j].first ;
1329- for (const auto & [modify_value, branch] : node.MatchModifies (j)) {
1303+ for (const DecisionNode::Match& match : node.Matches ()) {
1304+ for (const auto & [modify_value, branch] : match.modifies ) {
13301305 // Invariant: Modify branches are not Deny unless `modify_value ==
1331- // match_value `.
1332- RET_CHECK (!IsDeny (branch) || modify_value == match_value )
1306+ // match.value `.
1307+ RET_CHECK (!IsDeny (branch) || modify_value == match. value )
13331308 << " :\n "
13341309 << ToString (node);
13351310
0 commit comments