Skip to content

Commit

Permalink
[codegen] Add Map::clear_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Mar 27, 2024
1 parent 999e6a2 commit 4a4f7ac
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions phf_codegen/src/lib.rs
Expand Up @@ -198,6 +198,17 @@ impl<K: Hash + PhfHash + Eq + FmtConst> Map<K> {
self
}

/// Clears the entries currently in the builder.
///
/// Using a single builder and clearing it after calls to [`Self::build`] is more efficent
/// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`].
pub fn clear_entries(&mut self) -> &mut Map<K> {
self.keys.clear();
self.values.clear();

self
}

/// Calculate the hash parameters and return a struct implementing
/// [`Display`](::std::fmt::Display) which will print the constructed `phf::Map`.
///
Expand Down Expand Up @@ -302,6 +313,15 @@ impl<T: Hash + PhfHash + Eq + FmtConst> Set<T> {
self
}

/// Clears the entries currently in the builder.
///
/// Using a single builder and clearing it after calls to [`Self::build`] is more efficent
/// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`].
pub fn clear_entries(&mut self) -> &mut Set<T> {
self.map.clear_entries();
self
}

/// Calculate the hash parameters and return a struct implementing
/// [`Display`](::std::fmt::Display) which will print the constructed `phf::Set`.
///
Expand Down Expand Up @@ -358,6 +378,17 @@ impl<K: Hash + PhfHash + Eq + FmtConst> OrderedMap<K> {
self
}

/// Clears the entries currently in the builder.
///
/// Using a single builder and clearing it after calls to [`Self::build`] is more efficent
/// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`].
pub fn clear_entries(&mut self) -> &mut OrderedMap<K> {
self.keys.clear();
self.values.clear();

self
}

/// Calculate the hash parameters and return a struct implementing
/// [`Display`](::std::fmt::Display) which will print the constructed
/// `phf::OrderedMap`.
Expand Down Expand Up @@ -472,6 +503,15 @@ impl<T: Hash + PhfHash + Eq + FmtConst> OrderedSet<T> {
self
}

/// Clears the entries currently in the builder.
///
/// Using a single builder and clearing it after calls to [`Self::build`] is more efficent
/// than creating a new builder in a loop, as this can reuse heap allocations similar to [`Vec::clear`].
pub fn clear_entries(&mut self) -> &mut OrderedSet<T> {
self.map.clear_entries();
self
}

/// Calculate the hash parameters and return a struct implementing
/// [`Display`](::std::fmt::Display) which will print the constructed
/// `phf::OrderedSet`.
Expand Down

0 comments on commit 4a4f7ac

Please sign in to comment.