GithubHelp home page GithubHelp logo

takuyaa / yada Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 5.0 9.64 MB

Yada is a yet another double-array trie library aiming for fast search and compact data representation.

License: Apache License 2.0

Rust 100.00%

yada's People

Contributors

johtani avatar kampersanda avatar takuyaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

yada's Issues

Builder panics using this keyset

I found a keyset which cases the builder to panic.
Is it a bug or did I just miss something?

Code to reproduce

use yada::builder::DoubleArrayBuilder;

fn main() {
    let keyset = [
        ("goo", 1),
        ("mag", 2),
        ("gon", 3),
    ];
    let da_bytes: Option<Vec<u8>> = DoubleArrayBuilder::build(&keyset);
    println!("{:?}", da_bytes);
}

Resulting panic

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `103`,
 right: `0`', /home/<USER>/.cargo/registry/src/github.com-1ecc6299db9ec823/yada-0.5.0/src/builder.rs:201:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Add terminate char in builder?

Now, the builder expects that keys have a terminal character.
But, it is easy to use user only provides key and value.

What do you think?

DoubleArray::new() does not check untrusted source

DoubleArray::get_unit() calls slice::get_unchecked() internally, but this slice is not checked in DoubleArray::new().
So, it is possible to cause a segmentation fault even though the caller does not use unsafe blocks.

use yada::DoubleArray;

fn main() {
    let da = DoubleArray::new(vec![]);
    if let Some(index) = da.exact_match_search("example input") {
        dbg!(index);
    }
}
$ cargo run --release
...
[1]    81236 segmentation fault  cargo run --release

Solution 1: Change DoubleArray::new() to an unsafe function

This solution does not pay the additional runtime cost, but requires callers to be responsible for using the correct slice.

let da = unsafe { DoubleArray::new(trusted_bytes) };

Solution 2: Change slice::get_unchecked() to a checked function

The opposite of Solution 1.

let b = &self.0[index * UNIT_SIZE..(index + 1) * UNIT_SIZE];

or

let b = self.0.get(index * UNIT_SIZE..(index + 1) * UNIT_SIZE)
          .ok_or_else(|| ...)?;

Solution 3: Check the argument of DoubleArray::new()

This is too much work, but it does not require any responsibility on callers and does not pay any additional costs during the search.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.