git.delta.rocks / jrsonnet / refs/commits / 974f2c15c0a2

difftreelog

perf implement std.setMember in native

Yaroslav Bolyukin2023-01-20parent: #219e52a.patch.diff
in: master

3 files changed

modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
40pub use strings::*;40pub use strings::*;
41mod misc;41mod misc;
42pub use misc::*;42pub use misc::*;
43mod sets;
44pub use sets::*;
4345
44pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {46pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
45 let mut builder = ObjValueBuilder::new();47 let mut builder = ObjValueBuilder::new();
141 ("length", builtin_length::INST),143 ("length", builtin_length::INST),
142 ("startsWith", builtin_starts_with::INST),144 ("startsWith", builtin_starts_with::INST),
143 ("endsWith", builtin_ends_with::INST),145 ("endsWith", builtin_ends_with::INST),
146 // Sets
147 ("setMember", builtin_set_member::INST),
144 ]148 ]
145 .iter()149 .iter()
146 .cloned()150 .cloned()
addedcrates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth

no changes

modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
209 set(arr, keyF=id)::209 set(arr, keyF=id)::
210 std.uniq(std.sort(arr, keyF), keyF),210 std.uniq(std.sort(arr, keyF), keyF),
211211
212 setMember(x, arr, keyF=id)::
213 // TODO(dcunnin): Binary chop for O(log n) complexity
214 std.length(std.setInter([x], arr, keyF)) > 0,
215
216 setUnion(a, b, keyF=id)::212 setUnion(a, b, keyF=id)::
217 // NOTE: order matters, values in `a` win213 // NOTE: order matters, values in `a` win
218 local aux(a, b, i, j, acc) =214 local aux(a, b, i, j, acc) =