probabilistic_machines 0.1.4 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/Cargo.lock +22 -3
- data/Cargo.toml +2 -0
- data/README.md +166 -58
- data/ext/probabilistic_machines_native/core/Cargo.toml +10 -5
- data/ext/probabilistic_machines_native/core/src/countmin.rs +117 -88
- data/ext/probabilistic_machines_native/core/src/cuckoo.rs +109 -70
- data/ext/probabilistic_machines_native/core/src/hash.rs +9 -17
- data/ext/probabilistic_machines_native/core/src/hyperloglog.rs +104 -81
- data/ext/probabilistic_machines_native/core/src/lib.rs +131 -43
- data/ext/probabilistic_machines_native/core/src/tdigest.rs +176 -86
- data/ext/probabilistic_machines_native/core/src/topk.rs +253 -115
- data/ext/probabilistic_machines_native/ffi/Cargo.toml +5 -11
- data/ext/probabilistic_machines_native/ffi/src/countmin.rs +111 -70
- data/ext/probabilistic_machines_native/ffi/src/cuckoo.rs +102 -44
- data/ext/probabilistic_machines_native/ffi/src/data.rs +102 -55
- data/ext/probabilistic_machines_native/ffi/src/hyperloglog.rs +92 -49
- data/ext/probabilistic_machines_native/ffi/src/init.rs +15 -0
- data/ext/probabilistic_machines_native/ffi/src/lib.rs +74 -109
- data/ext/probabilistic_machines_native/ffi/src/tdigest.rs +91 -90
- data/ext/probabilistic_machines_native/ffi/src/topk.rs +181 -136
- data/lib/probabilistic_machines/version.rb +1 -1
- data/lib/probabilistic_machines.rb +40 -2
- data/sig/probabilistic_machines.rbs +129 -56
- metadata +2 -1
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
use std::cell::RefCell;
|
|
4
4
|
|
|
5
|
-
use bytes::Bytes;
|
|
6
|
-
use magnus::scan_args::scan_args;
|
|
7
5
|
use magnus::typed_data::Obj;
|
|
8
|
-
use magnus::{Error,
|
|
9
|
-
use
|
|
6
|
+
use magnus::{Error, RModule, RString, Ruby, Value, function, method, prelude::*};
|
|
7
|
+
use matryona_machines::ruby::integer;
|
|
8
|
+
use probabilistic_machines::{HyperLogLog, Refusal};
|
|
10
9
|
|
|
11
|
-
use crate::
|
|
10
|
+
use crate::data::bytes;
|
|
11
|
+
use crate::{Pinned, answer, decoded_or_refused, define_class, partner, pin, sizes, unsupported};
|
|
12
12
|
|
|
13
13
|
/// Register counts [`Sketch`] is monomorphised for.
|
|
14
14
|
const REGISTERS: [usize; 4] = [1024, 4096, 16384, 65536];
|
|
@@ -33,6 +33,9 @@ macro_rules! sketch {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/// The class, pinned at init.
|
|
37
|
+
static CLASS: Pinned = Pinned::new("probabilistic_machines");
|
|
38
|
+
|
|
36
39
|
#[magnus::wrap(class = "ProbabilisticMachines::HyperLogLog", free_immediately, size)]
|
|
37
40
|
struct Wrapper(RefCell<Sketch>);
|
|
38
41
|
|
|
@@ -40,7 +43,7 @@ const fn registers_of<const M: usize>(_: &HyperLogLog<M>) -> usize {
|
|
|
40
43
|
M
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
fn standard_error_of<const M: usize>(_: &HyperLogLog<M>) -> f64 {
|
|
46
|
+
const fn standard_error_of<const M: usize>(_: &HyperLogLog<M>) -> f64 {
|
|
44
47
|
HyperLogLog::<M>::standard_error()
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -52,52 +55,71 @@ fn boxed_new<const N: usize>() -> Box<HyperLogLog<N>> {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
#[inline(never)]
|
|
55
|
-
fn boxed_decode<const N: usize>(
|
|
58
|
+
fn boxed_decode<const N: usize>(frame: &[u8]) -> Result<Box<HyperLogLog<N>>, Refusal> {
|
|
56
59
|
let mut sketch = boxed_new::<N>();
|
|
57
|
-
sketch
|
|
58
|
-
.decode_into(frame)
|
|
59
|
-
.map_err(|error| codec_error(ruby, error))?;
|
|
60
|
+
sketch.decode_into(frame)?;
|
|
60
61
|
Ok(sketch)
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
/// The sketch a frame holds. A precision this build does not carry is read
|
|
65
|
+
/// as the smallest shape it does, which answers exactly what the core answers
|
|
66
|
+
/// a type of another shape: `Truncated`, `WrongStructure` or `WrongShape`.
|
|
67
|
+
fn decoded(frame: &[u8]) -> Result<Sketch, Refusal> {
|
|
68
|
+
Ok(match frame.get(1) {
|
|
69
|
+
Some(12) => Sketch::M4096(boxed_decode(frame)?),
|
|
70
|
+
Some(14) => Sketch::M16384(boxed_decode(frame)?),
|
|
71
|
+
Some(16) => Sketch::M65536(boxed_decode(frame)?),
|
|
72
|
+
Some(_) | None => Sketch::M1024(boxed_decode(frame)?),
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
impl Wrapper {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let
|
|
77
|
+
/// `HyperLogLog.new(registers)`. `RangeError` outside [`REGISTERS`].
|
|
78
|
+
fn new(ruby: &Ruby, registers: Value) -> Result<Self, Error> {
|
|
79
|
+
let registers: usize = integer(registers, "registers")?;
|
|
67
80
|
let sketch = match registers {
|
|
68
|
-
1024 => Sketch::M1024(boxed_new
|
|
69
|
-
4096 => Sketch::M4096(boxed_new
|
|
70
|
-
16384 => Sketch::M16384(boxed_new
|
|
71
|
-
65536 => Sketch::M65536(boxed_new
|
|
81
|
+
1024 => Sketch::M1024(boxed_new()),
|
|
82
|
+
4096 => Sketch::M4096(boxed_new()),
|
|
83
|
+
16384 => Sketch::M16384(boxed_new()),
|
|
84
|
+
65536 => Sketch::M65536(boxed_new()),
|
|
72
85
|
_ => return Err(unsupported(ruby, "registers", registers, ®ISTERS)),
|
|
73
86
|
};
|
|
74
87
|
Ok(Self(RefCell::new(sketch)))
|
|
75
88
|
}
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
/// `HyperLogLog.decode(bytes)`: a sketch, or the refusal symbol.
|
|
91
|
+
fn decode(ruby: &Ruby, bytes: Value) -> Result<Value, Error> {
|
|
92
|
+
let bytes = self::bytes(bytes, "bytes")?;
|
|
93
|
+
Ok(decoded_or_refused(
|
|
94
|
+
ruby,
|
|
95
|
+
decoded(&bytes).map(|held| Self(RefCell::new(held))),
|
|
96
|
+
))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn decode_into(ruby: &Ruby, this: Obj<Self>, bytes: Value) -> Result<Value, Error> {
|
|
100
|
+
this.check_frozen()?;
|
|
101
|
+
let bytes = self::bytes(bytes, "bytes")?;
|
|
102
|
+
let outcome = sketch!(&mut *this.0.borrow_mut(), |sketch| sketch
|
|
103
|
+
.decode_into(&bytes));
|
|
104
|
+
Ok(answer(ruby, outcome, "decoded"))
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
fn registers(&self) -> usize {
|
|
92
108
|
sketch!(&*self.0.borrow(), |sketch| registers_of(&**sketch))
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
fn add(
|
|
96
|
-
|
|
111
|
+
fn add(this: Obj<Self>, item: Value) -> Result<(), Error> {
|
|
112
|
+
this.check_frozen()?;
|
|
113
|
+
let item = bytes(item, "item")?;
|
|
114
|
+
sketch!(&mut *this.0.borrow_mut(), |sketch| sketch.add(&item));
|
|
115
|
+
Ok(())
|
|
97
116
|
}
|
|
98
117
|
|
|
99
|
-
fn add_hash(
|
|
100
|
-
|
|
118
|
+
fn add_hash(this: Obj<Self>, hash: Value) -> Result<(), Error> {
|
|
119
|
+
this.check_frozen()?;
|
|
120
|
+
let hash: u64 = integer(hash, "hash")?;
|
|
121
|
+
sketch!(&mut *this.0.borrow_mut(), |sketch| sketch.add_hash(hash));
|
|
122
|
+
Ok(())
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
fn estimate(&self) -> f64 {
|
|
@@ -112,20 +134,39 @@ impl Wrapper {
|
|
|
112
134
|
sketch!(&*self.0.borrow(), |sketch| sketch.is_empty())
|
|
113
135
|
}
|
|
114
136
|
|
|
115
|
-
|
|
137
|
+
/// `:merged`, or `:wrong_shape` for a sketch of another register count
|
|
138
|
+
/// (in Rust that merge does not compile).
|
|
139
|
+
fn merge(ruby: &Ruby, this: Obj<Self>, other: Value) -> Result<Value, Error> {
|
|
140
|
+
this.check_frozen()?;
|
|
141
|
+
let other: Obj<Self> = partner(ruby, &CLASS, other)?;
|
|
116
142
|
let source = other.0.borrow().clone();
|
|
117
|
-
match (&mut *
|
|
118
|
-
(Sketch::M1024(target), Sketch::M1024(source)) =>
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
let merged = match (&mut *this.0.borrow_mut(), &source) {
|
|
144
|
+
(Sketch::M1024(target), Sketch::M1024(source)) => {
|
|
145
|
+
target.merge(source);
|
|
146
|
+
Ok(())
|
|
147
|
+
}
|
|
148
|
+
(Sketch::M4096(target), Sketch::M4096(source)) => {
|
|
149
|
+
target.merge(source);
|
|
150
|
+
Ok(())
|
|
151
|
+
}
|
|
152
|
+
(Sketch::M16384(target), Sketch::M16384(source)) => {
|
|
153
|
+
target.merge(source);
|
|
154
|
+
Ok(())
|
|
155
|
+
}
|
|
156
|
+
(Sketch::M65536(target), Sketch::M65536(source)) => {
|
|
157
|
+
target.merge(source);
|
|
158
|
+
Ok(())
|
|
159
|
+
}
|
|
160
|
+
(
|
|
161
|
+
Sketch::M1024(_) | Sketch::M4096(_) | Sketch::M16384(_) | Sketch::M65536(_),
|
|
162
|
+
Sketch::M1024(_) | Sketch::M4096(_) | Sketch::M16384(_) | Sketch::M65536(_),
|
|
163
|
+
) => Err(Refusal::WrongShape),
|
|
164
|
+
};
|
|
165
|
+
Ok(answer(ruby, merged, "merged"))
|
|
125
166
|
}
|
|
126
167
|
|
|
127
|
-
fn
|
|
128
|
-
let frame = sketch!(&*
|
|
168
|
+
fn encoded(ruby: &Ruby, this: &Self) -> RString {
|
|
169
|
+
let frame = sketch!(&*this.0.borrow(), |sketch| sketch.encoded());
|
|
129
170
|
ruby.str_from_slice(&frame)
|
|
130
171
|
}
|
|
131
172
|
|
|
@@ -139,9 +180,11 @@ impl Wrapper {
|
|
|
139
180
|
}
|
|
140
181
|
|
|
141
182
|
pub fn define(ruby: &Ruby, module: RModule) -> Result<(), Error> {
|
|
142
|
-
let class =
|
|
143
|
-
class.
|
|
144
|
-
class.define_singleton_method("
|
|
183
|
+
let class = define_class(ruby, module, "HyperLogLog")?;
|
|
184
|
+
class.const_set("REGISTERS", sizes(ruby, ®ISTERS))?;
|
|
185
|
+
class.define_singleton_method("new", function!(Wrapper::new, 1))?;
|
|
186
|
+
class.define_singleton_method("decode", function!(Wrapper::decode, 1))?;
|
|
187
|
+
class.define_method("decode_into", method!(Wrapper::decode_into, 1))?;
|
|
145
188
|
class.define_method("registers", method!(Wrapper::registers, 0))?;
|
|
146
189
|
class.define_method("add", method!(Wrapper::add, 1))?;
|
|
147
190
|
class.define_method("add_hash", method!(Wrapper::add_hash, 1))?;
|
|
@@ -149,7 +192,7 @@ pub fn define(ruby: &Ruby, module: RModule) -> Result<(), Error> {
|
|
|
149
192
|
class.define_method("standard_error", method!(Wrapper::standard_error, 0))?;
|
|
150
193
|
class.define_method("empty?", method!(Wrapper::is_empty, 0))?;
|
|
151
194
|
class.define_method("merge", method!(Wrapper::merge, 1))?;
|
|
152
|
-
class.define_method("
|
|
195
|
+
class.define_method("encoded", method!(Wrapper::encoded, 0))?;
|
|
153
196
|
class.define_method("inspect", method!(Wrapper::inspect, 0))?;
|
|
154
|
-
|
|
197
|
+
pin::<Wrapper>(ruby, class, &CLASS)
|
|
155
198
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//! Private native entry point.
|
|
2
|
+
use magnus::{Error, Ruby};
|
|
3
|
+
|
|
4
|
+
use crate::{countmin, cuckoo, data, hyperloglog, tdigest, topk};
|
|
5
|
+
|
|
6
|
+
#[magnus::init]
|
|
7
|
+
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
8
|
+
let module = ruby.define_module("ProbabilisticMachines")?;
|
|
9
|
+
data::define(ruby, module)?;
|
|
10
|
+
hyperloglog::define(ruby, module)?;
|
|
11
|
+
countmin::define(ruby, module)?;
|
|
12
|
+
tdigest::define(ruby, module)?;
|
|
13
|
+
cuckoo::define(ruby, module)?;
|
|
14
|
+
topk::define(ruby, module)
|
|
15
|
+
}
|
|
@@ -1,140 +1,105 @@
|
|
|
1
1
|
//! Ruby bindings for the `probabilistic-machines` sketches.
|
|
2
2
|
//!
|
|
3
3
|
//! Every sketch is sized by a const generic, so each class dispatches the size
|
|
4
|
-
//! it is given to a fixed set of monomorphised variants
|
|
5
|
-
//! `
|
|
6
|
-
|
|
7
|
-
#![allow(clippy::needless_pass_by_value)]
|
|
4
|
+
//! it is given to a fixed set of monomorphised variants, listed in a class
|
|
5
|
+
//! constant, and raises `RangeError` for any other size. Refusals come back as
|
|
6
|
+
//! the `snake_case` symbol of the core's `Refusal` variant and never raise.
|
|
8
7
|
|
|
9
8
|
mod countmin;
|
|
10
9
|
mod cuckoo;
|
|
11
10
|
mod data;
|
|
12
11
|
mod hyperloglog;
|
|
12
|
+
mod init;
|
|
13
13
|
mod tdigest;
|
|
14
14
|
mod topk;
|
|
15
15
|
|
|
16
|
-
use
|
|
17
|
-
|
|
18
|
-
use
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/// `RangeError` magnus raises for it.
|
|
33
|
-
pub(crate) struct Whole<T>(pub(crate) T);
|
|
34
|
-
|
|
35
|
-
impl<T: TryConvert> TryConvert for Whole<T> {
|
|
36
|
-
fn try_convert(value: Value) -> Result<Self, Error> {
|
|
37
|
-
if Integer::from_value(value).is_none() {
|
|
38
|
-
return Err(not_whole(value));
|
|
39
|
-
}
|
|
40
|
-
T::try_convert(value).map(Self)
|
|
16
|
+
use magnus::{Error, RArray, RClass, RModule, Ruby, TypedData, Value, prelude::*, typed_data::Obj};
|
|
17
|
+
use matryona_machines::ruby::{Class, Registry, Symbols, class_name, exact_typed_with, symbol};
|
|
18
|
+
use probabilistic_machines::Refusal;
|
|
19
|
+
|
|
20
|
+
matryona_machines::symbols! {
|
|
21
|
+
/// The core's refusals, each the snake case of its variant.
|
|
22
|
+
Refusals for Refusal as "a refusal" {
|
|
23
|
+
Truncated => "truncated",
|
|
24
|
+
WrongStructure => "wrong_structure",
|
|
25
|
+
WrongShape => "wrong_shape",
|
|
26
|
+
Malformed => "malformed",
|
|
27
|
+
Full => "full",
|
|
28
|
+
Overflow => "overflow",
|
|
29
|
+
ZeroCount => "zero_count",
|
|
30
|
+
NotFinite => "not_finite",
|
|
31
|
+
InvalidWeight => "invalid_weight",
|
|
41
32
|
}
|
|
42
33
|
}
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ruby.exception_type_error(),
|
|
48
|
-
format!(
|
|
49
|
-
"no implicit conversion of {} into Integer: {}",
|
|
50
|
-
value.class(),
|
|
51
|
-
value.inspect()
|
|
52
|
-
),
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/// The one required keyword of a constructor.
|
|
57
|
-
pub(crate) fn required_kwarg<T: TryConvert>(keywords: RHash, name: &str) -> Result<T, Error> {
|
|
58
|
-
Ok(get_kwargs::<_, (T,), (), ()>(keywords, &[name], &[])?
|
|
59
|
-
.required
|
|
60
|
-
.0)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/// A keyword with a default the caller may leave out.
|
|
64
|
-
pub(crate) fn optional_kwarg<T: TryConvert>(
|
|
65
|
-
keywords: RHash,
|
|
66
|
-
name: &str,
|
|
67
|
-
) -> Result<Option<T>, Error> {
|
|
68
|
-
Ok(
|
|
69
|
-
get_kwargs::<_, (), (Option<T>,), ()>(keywords, &[], &[name])?
|
|
70
|
-
.optional
|
|
71
|
-
.0,
|
|
72
|
-
)
|
|
35
|
+
/// Ruby symbol of a refusal: the snake case of the core variant.
|
|
36
|
+
pub(crate) fn refusal(ruby: &Ruby, refused: Refusal) -> Value {
|
|
37
|
+
Refusals::symbol(ruby, refused).as_value()
|
|
73
38
|
}
|
|
74
39
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
40
|
+
/// A sketch class the binding defined, pinned at init so a merge can check
|
|
41
|
+
/// its partner's exact class without looking it up by name.
|
|
42
|
+
pub(crate) type Pinned = Registry<Class>;
|
|
43
|
+
|
|
44
|
+
/// The other operand of a merge: a `T` that is an instance of exactly the
|
|
45
|
+
/// class pinned in `held`, never a subclass instance. `TypeError` otherwise,
|
|
46
|
+
/// naming that class and the one received.
|
|
47
|
+
pub(crate) fn partner<T: TypedData>(
|
|
48
|
+
ruby: &Ruby,
|
|
49
|
+
held: &Pinned,
|
|
50
|
+
other: Value,
|
|
51
|
+
) -> Result<Obj<T>, Error> {
|
|
52
|
+
let class = held.get(ruby)?.get(ruby);
|
|
53
|
+
exact_typed_with(ruby, other, class, || {
|
|
54
|
+
format!("other must be a {class}, not {}", class_name(other))
|
|
55
|
+
})
|
|
80
56
|
}
|
|
81
57
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
pub(crate) fn codec_error(ruby: &Ruby, error: CodecError) -> Error {
|
|
90
|
-
Error::new(ruby.exception_arg_error(), format!("codec: {error}"))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
pub(crate) fn mismatch(ruby: &Ruby, name: &str) -> Error {
|
|
94
|
-
Error::new(
|
|
95
|
-
ruby.exception_arg_error(),
|
|
96
|
-
format!("the other {name} has a different shape"),
|
|
97
|
-
)
|
|
58
|
+
/// The object a `decode` built, or the refusal symbol when its frame was
|
|
59
|
+
/// refused.
|
|
60
|
+
pub(crate) fn decoded_or_refused<T: TypedData>(ruby: &Ruby, outcome: Result<T, Refusal>) -> Value {
|
|
61
|
+
match outcome {
|
|
62
|
+
Ok(object) => ruby.obj_wrap(object).as_value(),
|
|
63
|
+
Err(refused) => refusal(ruby, refused),
|
|
64
|
+
}
|
|
98
65
|
}
|
|
99
66
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
67
|
+
/// `honoured` as a symbol when the call was honoured, its refusal otherwise.
|
|
68
|
+
pub(crate) fn answer(ruby: &Ruby, outcome: Result<(), Refusal>, honoured: &str) -> Value {
|
|
69
|
+
match outcome {
|
|
70
|
+
Ok(()) => symbol(ruby, honoured).as_value(),
|
|
71
|
+
Err(refused) => refusal(ruby, refused),
|
|
72
|
+
}
|
|
105
73
|
}
|
|
106
74
|
|
|
107
|
-
|
|
75
|
+
/// A size this build carries no monomorphised variant for: rejected
|
|
76
|
+
/// configuration, so `RangeError`.
|
|
77
|
+
pub(crate) fn unsupported(ruby: &Ruby, name: &str, given: usize, supported: &[usize]) -> Error {
|
|
108
78
|
Error::new(
|
|
109
|
-
ruby.
|
|
110
|
-
format!("
|
|
79
|
+
ruby.exception_range_error(),
|
|
80
|
+
format!("{name} {given} is not supported, expected one of {supported:?}"),
|
|
111
81
|
)
|
|
112
82
|
}
|
|
113
83
|
|
|
114
|
-
///
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|class| Error::new(ruby.get_inner(*class), "the filter is full"),
|
|
120
|
-
)
|
|
84
|
+
/// The supported sizes as a frozen Array, for a class constant.
|
|
85
|
+
pub(crate) fn sizes(ruby: &Ruby, supported: &[usize]) -> RArray {
|
|
86
|
+
let array = ruby.ary_from_iter(supported.iter().copied());
|
|
87
|
+
array.freeze();
|
|
88
|
+
array
|
|
121
89
|
}
|
|
122
90
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
91
|
+
/// Defines `name` under `module` with no allocator of its own, so
|
|
92
|
+
/// `Class#allocate` cannot hand out an object the core never built.
|
|
93
|
+
pub(crate) fn define_class(ruby: &Ruby, module: RModule, name: &str) -> Result<RClass, Error> {
|
|
94
|
+
let class = module.define_class(name, ruby.class_object())?;
|
|
95
|
+
class.undef_default_alloc_func();
|
|
96
|
+
Ok(class)
|
|
128
97
|
}
|
|
129
98
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
countmin::define(ruby, module)?;
|
|
137
|
-
tdigest::define(ruby, module)?;
|
|
138
|
-
cuckoo::define(ruby, module)?;
|
|
139
|
-
topk::define(ruby, module)
|
|
99
|
+
/// Pins `class` into `held` (no lookup back by name) and fixes magnus's class
|
|
100
|
+
/// for the wrapped `T` to it: building a `T` never runs `Object.const_get`
|
|
101
|
+
/// later. Called from init once the class and its methods are defined.
|
|
102
|
+
pub(crate) fn pin<T: TypedData>(ruby: &Ruby, class: RClass, held: &Pinned) -> Result<(), Error> {
|
|
103
|
+
held.set(ruby, Class::pin_wrapped::<T>(ruby, class)?)
|
|
104
|
+
.map(drop)
|
|
140
105
|
}
|