Skip to content

Commit

Permalink
HashMap -> BTreeMap in labels maps for ordered output
Browse files Browse the repository at this point in the history
  • Loading branch information
Llandy3d committed Feb 24, 2024
1 parent 915e8cc commit efbe075
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ struct OutSample {
#[pyo3(get)]
suffix: String,
#[pyo3(get)]
labels: Option<HashMap<String, String>>,
labels: Option<BTreeMap<String, String>>,
#[pyo3(get)]
value: f64,
}

impl OutSample {
fn new(suffix: String, labels: Option<HashMap<String, String>>, value: f64) -> Self {
fn new(suffix: String, labels: Option<BTreeMap<String, String>>, value: f64) -> Self {
Self {
suffix,
labels,
Expand Down Expand Up @@ -447,7 +447,7 @@ impl RedisBackend {
}
PipelineResult::Hash(hash) => {
for (labels, value) in hash {
let labels_map: HashMap<String, String> = {
let labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => return Err(PyException::new_err(e.to_string())),
Expand Down Expand Up @@ -497,7 +497,7 @@ impl RedisBackend {
};

for (labels, value) in count_hash {
let labels_map: HashMap<String, String> = {
let labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => return Err(PyException::new_err(e.to_string())),
Expand All @@ -515,7 +515,7 @@ impl RedisBackend {
}

for (labels, value) in sum_hash {
let labels_map: HashMap<String, String> = {
let labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => return Err(PyException::new_err(e.to_string())),
Expand Down Expand Up @@ -582,7 +582,7 @@ impl RedisBackend {
samples_list.push(out_sample);
}
_ => {
let mut labels_map = HashMap::new();
let mut labels_map = BTreeMap::new();
labels_map.insert("le".to_string(), suffix.to_string());
let out_sample = OutSample::new(
"_bucket".to_string(),
Expand Down Expand Up @@ -631,7 +631,7 @@ impl RedisBackend {
match suffix {
"count" => {
for (labels, value) in hash {
let labels_map: HashMap<String, String> = {
let labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => {
Expand All @@ -652,7 +652,7 @@ impl RedisBackend {
}
"sum" => {
for (labels, value) in hash {
let labels_map: HashMap<String, String> = {
let labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => {
Expand All @@ -673,7 +673,7 @@ impl RedisBackend {
}
_ => {
for (labels, value) in hash {
let mut labels_map: HashMap<String, String> = {
let mut labels_map: BTreeMap<String, String> = {
match serde_json::from_str(labels) {
Ok(map) => map,
Err(e) => {
Expand Down

0 comments on commit efbe075

Please sign in to comment.