This commit is contained in:
@@ -11,3 +11,9 @@ pub extern "C" fn scm_from_utf8_string (
|
||||
let bytes = unsafe { slice::from_raw_parts (ptr, len) };
|
||||
scm::make_string (str::from_utf8 (bytes).unwrap ())
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn scm_hash (ptr : *const u8, len : usize) -> u64 {
|
||||
let bytes = unsafe { slice::from_raw_parts (ptr, len) };
|
||||
crate::obarray::hash (str::from_utf8 (bytes).unwrap ())
|
||||
}
|
||||
|
||||
@@ -3,8 +3,24 @@ use crate::scm::scm_bits;
|
||||
use crate::scm;
|
||||
|
||||
mod fnv1a;
|
||||
use fnv1a::{FNV1a, SymbolHash};
|
||||
|
||||
pub struct Obarray (HashMap <String, scm_bits>);
|
||||
pub struct Obarray (HashMap <String, scm_bits, SymbolHash>);
|
||||
|
||||
pub fn hash () {
|
||||
pub const fn new () -> Obarray {
|
||||
Obarray (HashMap::with_hasher (SymbolHash ()))
|
||||
}
|
||||
|
||||
pub fn hash (s : &str) -> u64 {
|
||||
let mut a : FNV1a = Default::default ();
|
||||
a.write (s.as_bytes ());
|
||||
return a.finish ()
|
||||
}
|
||||
|
||||
impl Obarray {
|
||||
pub fn insert (&mut self) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub static symbols : Obarray = new ();
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
use std::{collections::HashMap, hash::{BuildHasher, Hasher}};
|
||||
|
||||
pub struct FNV1a (u64);
|
||||
pub struct SymbolHash;
|
||||
pub struct SymbolHash ();
|
||||
|
||||
impl Default for FNV1a {
|
||||
fn default () -> Self {
|
||||
FNV1a (offset_basis)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hasher for FNV1a {
|
||||
fn finish (&self) -> u64 {
|
||||
@@ -24,5 +30,5 @@ impl BuildHasher for SymbolHash {
|
||||
}
|
||||
}
|
||||
|
||||
const offset_basis : u64 = 0xcbf29ce484222325;
|
||||
const prime : u64 = 0x100000001b3;
|
||||
pub const offset_basis : u64 = 0xcbf29ce484222325;
|
||||
pub const prime : u64 = 0x100000001b3;
|
||||
|
||||
@@ -9,7 +9,7 @@ pub type scm_bits = u64;
|
||||
|
||||
pub const tc2_int : u64 = 2;
|
||||
pub const tc3_cons : u64 = 0;
|
||||
pub const tc7_weak_set : u64 = 0x55;
|
||||
pub const tc7_obarray : u64 = 0x55;
|
||||
pub const tc7_symbol : u64 = 0x05;
|
||||
pub const tc7_string : u64 = 0x15;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user