Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use hashbrown as internal hashmap #146

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;