11use std:: {
2- collections:: BTreeMap ,
2+ collections:: { BTreeMap , BTreeSet } ,
33 convert:: TryFrom ,
44 error,
55 fmt:: { Display , Formatter , Result as FmtResult } ,
@@ -62,15 +62,15 @@ pub(crate) fn get_all_node_records(snapshot: &RegistrySnapshot) -> BTreeMap<Node
6262/// Returns all replica version records in the snapshot.
6363pub ( crate ) fn get_all_replica_version_records (
6464 snapshot : & RegistrySnapshot ,
65- ) -> Vec < ( String , ReplicaVersionRecord ) > {
66- let mut replica_versions = Vec :: new ( ) ;
65+ ) -> BTreeMap < String , ReplicaVersionRecord > {
66+ let mut replica_versions = BTreeMap :: new ( ) ;
6767 for ( k, v) in snapshot {
6868 if let Some ( key) = str:: from_utf8 ( k)
6969 . unwrap ( )
7070 . strip_prefix ( REPLICA_VERSION_KEY_PREFIX )
7171 {
7272 let record = ReplicaVersionRecord :: decode ( v. as_slice ( ) ) . unwrap ( ) ;
73- replica_versions. push ( ( key. to_owned ( ) , record) ) ;
73+ replica_versions. insert ( key. to_owned ( ) , record) ;
7474 }
7575 }
7676
@@ -114,12 +114,12 @@ pub(crate) fn get_all_chain_key_signing_subnet_list_records(
114114// Retrieve all HostOS version records
115115pub ( crate ) fn get_all_hostos_version_records (
116116 snapshot : & RegistrySnapshot ,
117- ) -> Vec < HostosVersionRecord > {
118- let mut result = Vec :: new ( ) ;
117+ ) -> BTreeSet < HostosVersionRecord > {
118+ let mut result = BTreeSet :: new ( ) ;
119119 for ( k, v) in snapshot {
120120 if k. starts_with ( HOSTOS_VERSION_KEY_PREFIX . as_bytes ( ) ) {
121121 let hostos_version_record = HostosVersionRecord :: decode ( v. as_slice ( ) ) . unwrap ( ) ;
122- result. push ( hostos_version_record) ;
122+ result. insert ( hostos_version_record) ;
123123 }
124124 }
125125
@@ -147,8 +147,8 @@ pub(crate) fn get_api_boundary_node_records_from_snapshot(
147147/// Returns an all api boundary node ids record from the registry snapshot.
148148pub ( crate ) fn get_api_boundary_node_ids_from_snapshot (
149149 snapshot : & RegistrySnapshot ,
150- ) -> Result < Vec < NodeId > , InvariantCheckError > {
151- let api_bn_ids : Result < Vec < NodeId > , InvariantCheckError > = snapshot
150+ ) -> Result < BTreeSet < NodeId > , InvariantCheckError > {
151+ snapshot
152152 . keys ( )
153153 . cloned ( )
154154 . map ( |key| {
@@ -157,15 +157,13 @@ pub(crate) fn get_api_boundary_node_ids_from_snapshot(
157157 source : None ,
158158 } )
159159 } )
160- . collect :: < Result < Vec < String > , InvariantCheckError > > ( )
160+ . collect :: < Result < BTreeSet < String > , InvariantCheckError > > ( )
161161 . map ( |keys| {
162162 keys. into_iter ( )
163163 . filter_map ( |key_str| get_api_boundary_node_record_node_id ( & key_str) )
164164 . map ( NodeId :: from)
165165 . collect ( )
166- } ) ;
167-
168- api_bn_ids
166+ } )
169167}
170168
171169/// Returns node record from the snapshot corresponding to a key.
@@ -185,7 +183,7 @@ pub(crate) fn get_node_record_from_snapshot(
185183 . transpose ( )
186184}
187185
188- pub ( crate ) fn get_subnet_ids_from_snapshot ( snapshot : & RegistrySnapshot ) -> Vec < SubnetId > {
186+ pub ( crate ) fn get_subnet_ids_from_snapshot ( snapshot : & RegistrySnapshot ) -> BTreeSet < SubnetId > {
189187 get_value_from_snapshot :: < SubnetListRecord > ( snapshot, make_subnet_list_record_key ( ) )
190188 . map ( |r| {
191189 r. subnets
0 commit comments