Skip to content

Commit

Permalink
remove SimpleVob dep from derivre
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jul 3, 2024
1 parent 19432bf commit a8d036d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion controllers/derivre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ name = "derivre"

[dependencies]
ahash = "0.8.11"
aici_abi = { path = "../aici_abi" }
anyhow = "1.0.75"
bytemuck = "1.16.0"
bytemuck_derive = "1.6.1"
Expand Down
13 changes: 8 additions & 5 deletions controllers/derivre/src/bytecompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, hash::Hash};

use crate::{
ast::{byteset_contains, byteset_set, Expr, ExprSet},
ExprRef, SimpleVob,
ExprRef,
};

pub struct ByteCompressor {
Expand Down Expand Up @@ -82,12 +82,12 @@ impl ByteCompressor {
self.mapping = vec![INVALID_MAPPING; exprset.alphabet_size()];

let mut todo = rx_list.to_vec();
let mut visited = SimpleVob::alloc(exprset.len());
let mut visited = vec![false; exprset.len()];
while let Some(e) = todo.pop() {
if visited.get(e.as_usize()) {
if visited[e.as_usize()] {
continue;
}
visited.set(e.as_usize(), true);
visited[e.as_usize()] = true;
todo.extend_from_slice(exprset.get_args(e));
match exprset.get(e) {
Expr::Byte(b) => {
Expand All @@ -109,7 +109,10 @@ impl ByteCompressor {
if num <= 64 {
self.compress_bytesets(|_| 0u64, |v, idx| *v |= 1 << idx);
} else {
self.compress_bytesets(|size| SimpleVob::alloc(size), |v, idx| v.set(idx, true));
self.compress_bytesets(
|size| vec![0u32; (size + 31) / 32],
|v, idx| v[idx / 32] |= 1 << (idx % 32),
);
}

let mut trg = ExprSet::new(self.alphabet_size);
Expand Down
3 changes: 0 additions & 3 deletions controllers/derivre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ mod syntax;
pub use ast::{ExprRef, NextByte};
pub use regex::{AlphabetInfo, Regex, StateID};

use aici_abi::svob;
pub use svob::{SimpleVob, SimpleVobIter, TokenId};

pub use regexbuilder::{RegexAst, RegexBuilder};

pub use mapper::map_ast; // utility function
Expand Down
3 changes: 2 additions & 1 deletion controllers/llguidance_ctrl/src/earley/regexvec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use aici_abi::svob::SimpleVob;
use derivre::raw::{DerivCache, ExprSet, NextByteCache, VecHashCons};
use std::fmt::Debug;

pub use derivre::{AlphabetInfo, ExprRef, NextByte, SimpleVob, StateID};
pub use derivre::{AlphabetInfo, ExprRef, NextByte, StateID};

#[derive(Clone)]
pub struct RegexVec {
Expand Down
3 changes: 1 addition & 2 deletions controllers/llguidance_ctrl/src/tokenparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use crate::{
api::{GenGrammarOptions, TopLevelGrammar},
earley::{grammars_from_json, CGrammar, CSymIdx, ModelVariable, Parser, ParserStats},
};
use aici_abi::{MidProcessArg, MidProcessResult, TokenId, TokenizerEnv};
use aici_abi::{svob::SimpleVob, MidProcessArg, MidProcessResult, TokenId, TokenizerEnv};
use anyhow::Result;
use derivre::SimpleVob;
use serde_json::json;

macro_rules! infoln {
Expand Down

0 comments on commit a8d036d

Please sign in to comment.