feat: use hashbrown

This commit is contained in:
2025-05-17 19:45:41 +08:00
parent fb14027845
commit 7b55a15281
12 changed files with 89 additions and 34 deletions

View File

@@ -1,8 +1,7 @@
use std::collections::HashSet;
use hashbrown::{HashMap, HashSet};
use derive_more::Constructor;
use itertools::Itertools;
use rpds::HashTrieMap;
use crate::error::Result;
use crate::vm::{Env, VM};
@@ -13,25 +12,25 @@ use super::Value;
#[repr(C)]
#[derive(Debug, Constructor, Clone, PartialEq)]
pub struct AttrSet<'vm> {
data: HashTrieMap<usize, Value<'vm>>,
data: HashMap<usize, Value<'vm>>,
}
impl<'vm> AttrSet<'vm> {
pub fn empty() -> Self {
AttrSet {
data: HashTrieMap::new(),
data: HashMap::new(),
}
}
pub fn push_attr_force(&mut self, sym: usize, val: Value<'vm>) {
self.data.insert_mut(sym, val);
self.data.insert(sym, val);
}
pub fn push_attr(&mut self, sym: usize, val: Value<'vm>) {
if self.data.get(&sym).is_some() {
todo!()
}
self.data.insert_mut(sym, val);
self.data.insert(sym, val);
}
pub fn select(&self, sym: usize) -> Option<Value<'vm>> {
@@ -57,11 +56,11 @@ impl<'vm> AttrSet<'vm> {
}
}
pub fn as_inner(&self) -> &HashTrieMap<usize, Value<'vm>> {
pub fn as_inner(&self) -> &HashMap<usize, Value<'vm>> {
&self.data
}
pub fn from_inner(data: HashTrieMap<usize, Value<'vm>>) -> Self {
pub fn from_inner(data: HashMap<usize, Value<'vm>>) -> Self {
Self { data }
}

View File

@@ -1,4 +1,4 @@
use std::collections::HashSet;
use hashbrown::HashSet;
use derive_more::Constructor;
use rpds::Vector;

View File

@@ -1,6 +1,6 @@
use std::cell::OnceCell;
use std::cell::RefCell;
use std::collections::HashSet;
use hashbrown::HashSet;
use std::hash::Hash;
use std::rc::Rc;
@@ -219,11 +219,11 @@ impl<'vm> Value<'vm> {
}
}
pub fn eq(self, other: Self) -> Self {
pub fn eq(self, other: Self, vm: &'vm VM<'_>) -> Self {
use Const::Bool;
match (self, other) {
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
(s, other) => VmConst(Bool(s == other)),
(s, other) => VmConst(Bool(s.eq_impl(&other, vm))),
}
}

View File

@@ -1,3 +1,4 @@
use hashbrown::HashMap;
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use std::ops::Deref;
use std::sync::LazyLock;
@@ -5,7 +6,7 @@ use std::sync::LazyLock;
use derive_more::{Constructor, IsVariant, Unwrap};
use ecow::EcoString;
use regex::Regex;
use rpds::{HashTrieMap, VectorSync};
use rpds::VectorSync;
use super::common::*;
@@ -59,7 +60,7 @@ impl Symbol {
#[derive(Constructor, Clone, PartialEq)]
pub struct AttrSet {
data: HashTrieMap<Symbol, Value>,
data: HashMap<Symbol, Value>,
}
impl Debug for AttrSet {