Skip to content

Commit

Permalink
Merge pull request #182 from zhang-accounting/feat/python-binding
Browse files Browse the repository at this point in the history
feat: add python binding
  • Loading branch information
Kilerd authored Nov 1, 2023
2 parents 056b73e + 8f4102f commit 2705c69
Show file tree
Hide file tree
Showing 15 changed files with 692 additions and 40 deletions.
176 changes: 156 additions & 20 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ members = [
"extensions/*",
"server",
"cli",
"wasm"
"wasm",
"bindings/python"
]

[profile.dev]
Expand Down
12 changes: 6 additions & 6 deletions ast/src/utils/multi_value_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<Key: Eq + Hash, Value> Default for MultiValueMap<Key, Value> {

impl<Key: Hash + Eq, Value> MultiValueMap<Key, Value> {
pub fn insert(&mut self, key: Key, value: Value) {
let key_store = self.inner.entry(key).or_insert_with(Vec::new);
let key_store = self.inner.entry(key).or_default();
key_store.push(value);
}

Expand All @@ -27,18 +27,18 @@ impl<Key: Hash + Eq, Value> MultiValueMap<Key, Value> {
Key: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.inner.get(key.borrow()).and_then(|store| store.get(0))
self.inner.get(key).and_then(|store| store.get(0))
}

pub fn pop_one<Q>(&mut self, key: &Q) -> Option<Value>
where
Key: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
let value_len = self.inner.get(key.borrow()).map(|values| values.len());
let value_len = self.inner.get(key).map(|values| values.len());
match value_len {
Some(1) => self.inner.remove(key.borrow()).and_then(|mut values| values.pop()),
Some(_) => self.inner.get_mut(key.borrow()).map(|values| values.remove(0)),
Some(1) => self.inner.remove(key).and_then(|mut values| values.pop()),
Some(_) => self.inner.get_mut(key).map(|values| values.remove(0)),
None => None,
}
}
Expand All @@ -48,7 +48,7 @@ impl<Key: Hash + Eq, Value> MultiValueMap<Key, Value> {
Key: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.inner.get(key.borrow()).map(|it| it.iter().collect_vec()).unwrap_or_default()
self.inner.get(key).map(|it| it.iter().collect_vec()).unwrap_or_default()
}
}
impl<Key: Hash + Eq + Clone, Value> MultiValueMap<Key, Value> {
Expand Down
Loading

0 comments on commit 2705c69

Please sign in to comment.