takuyaa / yada Goto Github PK
View Code? Open in Web Editor NEWYada is a yet another double-array trie library aiming for fast search and compact data representation.
License: Apache License 2.0
Yada is a yet another double-array trie library aiming for fast search and compact data representation.
License: Apache License 2.0
I found a keyset which cases the builder to panic.
Is it a bug or did I just miss something?
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);
}
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
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?
Hi,
We are using yada in Lindera.
I got an error from yada for building ipadic neologd dictionary with lindera-ipadic-neologd-builder.
See the detail of error in this PR
Lindera needs DoubleArray is Clone-able for some reason.
Can make DoubleArray struct Clone-able?
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
DoubleArray::new()
to an unsafe functionThis 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) };
slice::get_unchecked()
to a checked functionThe 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(|| ...)?;
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.