Skip to content

Commit

Permalink
use hashbrown as internal hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
CrockAgile committed Jan 7, 2024
1 parent f2da5f3 commit 9d81ff0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ missing_const_for_fn = "deny"
tracing = { version = "0.1.37", optional = true }
tracing-subscriber = { version = "0.3.16", optional = true, features = ["env-filter"] }
tracing-flame = { version = "0.2.0", optional = true }
hashbrown = "0.14.3"

[dependencies.rand]
version = "0.8.0"
Expand Down
2 changes: 1 addition & 1 deletion src/earley/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct Production<'gram> {
}

type ProdArena<'gram> = AppendOnlyVec<Production<'gram>, ProductionId>;
type ProdTermMap<'gram> = std::collections::HashMap<&'gram crate::Term, Vec<ProductionId>>;
type ProdTermMap<'gram> = crate::HashMap<&'gram crate::Term, Vec<ProductionId>>;

/// Similar to [`crate::Grammar`], but using [`Production`] and tables useful for parsing.
#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/earley/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod traversal;
use crate::{tracing, ParseTree, ParseTreeNode, Term};
use grammar::{ParseGrammar, Production};
use input_range::InputRange;
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
use std::collections::{BTreeSet, HashSet, VecDeque};
use traversal::{TermMatch, Traversal, TraversalId, TraversalTree};

pub fn parse<'gram>(
Expand Down Expand Up @@ -224,8 +224,8 @@ impl<'gram> CompletionKey<'gram> {

#[derive(Debug, Default)]
pub(crate) struct CompletionMap<'gram> {
incomplete: HashMap<CompletionKey<'gram>, BTreeSet<TraversalId>>,
complete: HashMap<CompletionKey<'gram>, BTreeSet<TraversalId>>,
incomplete: crate::HashMap<CompletionKey<'gram>, BTreeSet<TraversalId>>,
complete: crate::HashMap<CompletionKey<'gram>, BTreeSet<TraversalId>>,
}

impl<'gram> CompletionMap<'gram> {
Expand Down
5 changes: 2 additions & 3 deletions src/earley/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
append_vec::{append_only_vec_id, AppendOnlyVec},
tracing, Term,
};
use std::collections::HashMap;

append_only_vec_id!(pub(crate) TraversalId);

Expand Down Expand Up @@ -55,8 +54,8 @@ struct TraversalRoot {
}

type TraversalArena<'gram> = AppendOnlyVec<Traversal<'gram>, TraversalId>;
type TreeRootMap = HashMap<TraversalRoot, TraversalId>;
type TreeEdgeMap<'gram> = HashMap<TraversalEdge<'gram>, TraversalId>;
type TreeRootMap = crate::HashMap<TraversalRoot, TraversalId>;
type TreeEdgeMap<'gram> = crate::HashMap<TraversalEdge<'gram>, TraversalId>;

/// Iterator of [`TermMatch`] which resulted in the [`Traversal`].
/// Walks a [`TraversalTree`] from [`TraversalRoot`] along [`TraversalEdge`].
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ pub use crate::expression::Expression;
pub use crate::grammar::{Grammar, ParseTree, ParseTreeNode};
pub use crate::production::Production;
pub use crate::term::Term;

pub(crate) use hashbrown::HashMap;

0 comments on commit 9d81ff0

Please sign in to comment.