Skip to content

Commit

Permalink
switch to hashbrown (to use ahash)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Jan 8, 2024
1 parent 879e496 commit fd3afb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nusamai-plateau/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nusamai-citygml = { path = "../nusamai-citygml", features = ["serde"]}
chrono = { version = "0.4.31", features = ["serde"], default-features = false }
url = "2.5.0"
stretto = "0.8.2"
ahash = "0.8.7"
hashbrown = "0.14.3"

[dev-dependencies]
zstd = { version = "0.13.0", features = ["zdict_builder"] }
Expand Down
10 changes: 5 additions & 5 deletions nusamai-plateau/src/codelist/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;

use super::xml::{parse_dictionary, Definition};
use nusamai_citygml::codelist::CodeResolver;
use nusamai_citygml::ParseError;
use hashbrown::HashMap;
use stretto::Cache;
use url::Url;

type Map = HashMap<String, Definition, ahash::RandomState>;
use nusamai_citygml::codelist::CodeResolver;
use nusamai_citygml::ParseError;

pub struct Resolver {
cache: Cache<PathBuf, Map>,
cache: Cache<PathBuf, HashMap<String, Definition>>,
}

impl Resolver {
Expand Down
12 changes: 6 additions & 6 deletions nusamai-plateau/src/codelist/xml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use hashbrown::HashMap;
use std::io::BufRead;

use quick_xml::events::Event;
Expand All @@ -7,8 +7,6 @@ use quick_xml::name::ResolveResult::Bound;
use nusamai_citygml::namespace::GML31_NS;
use nusamai_citygml::ParseError;

type Map = HashMap<String, Definition, ahash::RandomState>;

#[derive(Debug)]
pub struct Definition {
value: String,
Expand Down Expand Up @@ -54,7 +52,7 @@ fn expect_text<R: BufRead>(

fn parse_definition<R: BufRead>(
reader: &mut quick_xml::NsReader<R>,
definitions: &mut Map,
definitions: &mut HashMap<String, Definition>,
buf: &mut Vec<u8>,
buf2: &mut Vec<u8>,
) -> Result<(), ParseError> {
Expand Down Expand Up @@ -106,14 +104,16 @@ fn parse_definition<R: BufRead>(
}
}

pub fn parse_dictionary<R: BufRead>(src_reader: R) -> Result<Map, ParseError> {
pub fn parse_dictionary<R: BufRead>(
src_reader: R,
) -> Result<HashMap<String, Definition>, ParseError> {
let mut reader = quick_xml::NsReader::from_reader(src_reader);
reader.trim_text(true);
reader.expand_empty_elements(true);
let mut depth = 0;
let mut buf = Vec::new();
let mut buf2 = Vec::new();
let mut definitions = Map::default();
let mut definitions = HashMap::default();

loop {
match reader.read_event_into(&mut buf) {
Expand Down

0 comments on commit fd3afb6

Please sign in to comment.