Skip to content

Commit

Permalink
Merge pull request #28 from LucaCappelletti94/master
Browse files Browse the repository at this point in the history
Updated version of pull request #25
  • Loading branch information
shanecelis authored Apr 22, 2024
2 parents ad075ed + 065cd70 commit 6d8fafd
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 307 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Clippy

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
clippy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install Clippy
run:
rustup toolchain install nightly --component clippy
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Run clippy
run: cargo clippy --all-features
- name: Run clippy without rayon
run: cargo clippy --no-default-features --features="serde"
- name: Run tests
run: cargo test --all-features
- name: Run tests without rayon
run: cargo test --no-default-features --features="serde"
- name: Run tests release
run: cargo test --release --all-features
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.3.1]
- Added derives across all data structures, including:
- `Clone`
- `Debug`
- serde's `Serialize` & `Deserialize`, available under the feature `serde`.
- [mem-dbg](https://github.com/zommiommy/mem_dbg-rs)'s `MemDbg` & `MemSize`, available under the feature `mem-dbg`.
- Moved rayon, which is optionally used in dependency crates, under the feature `rayon`.
- Switched from Travis-CI to GitHub Actions.
- Fixed several code smells as reported by clippy.
- Extended documentation & doctests.

## [v0.3.0]
- Use iterators for search results.

Expand Down
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trie-rs"
version = "0.3.0"
version = "0.3.1"
authors = ["Sho Nakatani <lay.sakura@gmail.com>", "Shane Celis <shane.celis@gmail.com>"]
description = "Memory efficient trie (prefix tree) and map library based on LOUDS"
readme = "README.md"
Expand All @@ -9,10 +9,12 @@ repository = "https://github.com/laysakura/trie-rs"
homepage = "https://github.com/laysakura/trie-rs"
keywords = ["trie", "louds", "succinct"] # up to 5 keywords, each keyword should have <= 20 chars
categories = ["compression", "data-structures"]
edition = "2018"
edition = "2021"

[dependencies]
louds-rs = "0.6"
mem_dbg = { version = "0.1.4", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
criterion = "0.2"
Expand All @@ -23,3 +25,8 @@ version-sync = "0.9"
[[bench]]
name = "bench"
harness = false

[features]
serde = ["louds-rs/serde", "dep:serde"]
mem_dbg = ["louds-rs/mem_dbg", "dep:mem_dbg"]
rayon = ["louds-rs/rayon"]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Memory efficient trie (prefix tree) and map library based on LOUDS.
|
[Changelog](https://github.com/laysakura/trie-rs/blob/master/CHANGELOG.md)

[![Build Status](https://travis-ci.com/laysakura/trie-rs.svg?branch=master)](https://travis-ci.com/laysakura/trie-rs)
[![GitHub Actions Status](https://github.com/laysakura/trie-rs/actions/workflows/clippy.yml/badge.svg)](https://github.com/laysakura/trie-rs/actions)
[![Travis Status](https://travis-ci.com/laysakura/trie-rs.svg?branch=master)](https://travis-ci.com/laysakura/trie-rs)
[![Crates.io Version](https://img.shields.io/crates/v/trie-rs.svg)](https://crates.io/crates/trie-rs)
[![Crates.io Downloads](https://img.shields.io/crates/d/trie-rs.svg)](https://crates.io/crates/trie-rs)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.33+-lightgray.svg)](https://github.com/laysakura/trie-rs#rust-version-supports)
Expand Down Expand Up @@ -78,7 +79,7 @@ assert_eq!(
### Using with Various Data Types
`TrieBuilder` is implemented using generic type like following:

```rust
```ignore
impl<Label: Ord> TrieBuilder<Label> {
...
pub fn push<Arr: AsRef<[Label]>>(&mut self, word: Arr) where Label: Clone { ... }
Expand Down
9 changes: 7 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ mod trie {
|trie| {
// iter_batched() does not properly time `routine` time when `setup` time is far longer than `routine` time.
// Tested function takes too short compared to build(). So loop many times.
let result = trie.common_prefix_search::<Vec<u8>, _>("すしをにぎる").next().is_some();
let result = trie
.common_prefix_search::<Vec<u8>, _>("すしをにぎる")
.next()
.is_some();
for _ in 0..(times - 1) {
trie.common_prefix_search::<Vec<u8>, _>("すしをにぎる").next().is_some();
trie.common_prefix_search::<Vec<u8>, _>("すしをにぎる")
.next()
.is_some();
}

assert_eq!(result, true);
Expand Down
11 changes: 8 additions & 3 deletions src/inc_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
//! the number of entries in the trie. Consider this loop where we simulate
//! accumulating a query.
//!
//! ```ignore
//! ```rust
//! use trie_rs::Trie;
//!
//! let q = "appli"; // query string
//! let mut is_match: bool;
//! for i = 0..q.len() {
//! is_match = trie.exact_match(q[0..i]);
//! let trie = Trie::from_iter(vec!["appli", "application"]);
//! for i in 0..q.len() - 1 {
//! assert!(!trie.exact_match(&q[0..i]));
//! }
//! assert!(trie.exact_match(q));
//! ```
//!
//! Building the query one "character" at a time and `exact_match()`ing each
Expand All @@ -37,6 +41,7 @@
use crate::map::Trie;
use louds_rs::LoudsNodeNum;

#[derive(Debug, Clone)]
/// An incremental search of the trie.
pub struct IncSearch<'a, Label, Value> {
trie: &'a Trie<Label, Value>,
Expand Down
14 changes: 13 additions & 1 deletion src/internal_data_structure/naive_trie.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
pub mod naive_trie;
pub mod naive_trie_b_f_iter;
pub mod naive_trie_impl;

#[cfg(feature = "mem_dbg")]
use mem_dbg::MemDbg;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg, mem_dbg::MemSize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Naive trie with ordered Label sequence in edges.
///
/// The following naive trie contains these words.
Expand Down Expand Up @@ -72,11 +78,17 @@ pub enum NaiveTrie<Label, Value> {
PhantomSibling,
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg, mem_dbg::MemSize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NaiveTrieRoot<Label, Value> {
/// Sorted by Label's order.
children: Vec<NaiveTrie<Label, Value>>,
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg, mem_dbg::MemSize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NaiveTrieIntermOrLeaf<Label, Value> {
/// Sorted by Label's order.
children: Vec<NaiveTrie<Label, Value>>,
Expand Down
6 changes: 6 additions & 0 deletions src/internal_data_structure/naive_trie/naive_trie_b_f_iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use super::NaiveTrie;
use std::collections::VecDeque;

#[cfg(feature = "mem_dbg")]
use mem_dbg::MemDbg;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg, mem_dbg::MemSize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Iterates over NaiveTrie in Breadth-First manner.
pub struct NaiveTrieBFIter<Label, Value> {
unvisited: VecDeque<NaiveTrie<Label, Value>>,
Expand Down
3 changes: 2 additions & 1 deletion src/iter/keys.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[derive(Debug, Clone)]
/// Strips off `Value`s from [crate::map::Trie].
pub struct Keys<I>(I);

impl<I> Keys<I> {
///
///Creates a new `Keys` iterator.
pub fn new(iter: I) -> Self {
Self(iter)
}
Expand Down
1 change: 1 addition & 0 deletions src/iter/postfix_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::try_collect::{TryCollect, TryFromIterator};
use louds_rs::LoudsNodeNum;
use std::marker::PhantomData;

#[derive(Debug, Clone)]
/// Iterates through all the postfixes of a matching query.
pub struct PostfixIter<'a, Label, Value, C, M> {
trie: &'a Trie<Label, Value>,
Expand Down
1 change: 1 addition & 0 deletions src/iter/prefix_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::try_collect::{TryCollect, TryFromIterator};
use louds_rs::LoudsNodeNum;
use std::marker::PhantomData;

#[derive(Debug, Clone)]
/// Iterates through all the common prefixes of a given query.
pub struct PrefixIter<'a, Label, Value, C, M> {
trie: &'a Trie<Label, Value>,
Expand Down
1 change: 1 addition & 0 deletions src/iter/search_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::try_collect::{Collect, TryCollect, TryFromIterator};
use louds_rs::LoudsNodeNum;
use std::marker::PhantomData;

#[derive(Debug, Clone)]
/// Iterates through all the matches of a query.
pub struct SearchIter<'a, Label, Value, C, M> {
prefix: Vec<Label>,
Expand Down
Loading

0 comments on commit 6d8fafd

Please sign in to comment.