Initial commit
This commit is contained in:
10
src/genAttrs.nix
Normal file
10
src/genAttrs.nix
Normal file
@@ -0,0 +1,10 @@
|
||||
lib:
|
||||
let
|
||||
genAttrsOld = names: f: lib.listToAttrs (map (n: lib.nameValuePair n (f n)) names);
|
||||
genAttrsNew = names: f: lib.listToAttrs (map (n: { name = n; value = f n; }) names);
|
||||
|
||||
bigdata = lib.imap0 (i: _: toString i) (lib.replicate 999999 null);
|
||||
in {
|
||||
old = genAttrsOld bigdata (_: null);
|
||||
new = genAttrsNew bigdata (_: null);
|
||||
}
|
||||
10
src/keepAttrs.nix
Normal file
10
src/keepAttrs.nix
Normal file
@@ -0,0 +1,10 @@
|
||||
lib:
|
||||
let
|
||||
keepAttrsOld = attrs: names: lib.filterAttrs (n: _: builtins.elem n names) attrs;
|
||||
keepAttrsNew = attrs: names: builtins.intersectAttrs (lib.genAttrs names (_: null)) attrs;
|
||||
|
||||
bigdata = lib.genAttrs (lib.imap0 (i: _: toString i) (lib.replicate 999999 null)) (_: null);
|
||||
in {
|
||||
old = keepAttrsOld bigdata [ "123" "456" ];
|
||||
new = keepAttrsNew bigdata [ "123" "456" ];
|
||||
}
|
||||
17
src/subtractLists.nix
Normal file
17
src/subtractLists.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
lib:
|
||||
let
|
||||
# O(nm)
|
||||
subtractListsOld = e: builtins.filter (x: !(builtins.elem x e));
|
||||
|
||||
# O(n + m) (hopefully)
|
||||
subtractListsNew = e: let
|
||||
# Assuming genAttrs is O(n)
|
||||
e' = lib.genAttrs e (_: null);
|
||||
# Assuming hasAttr is O(1)
|
||||
in builtins.filter (x: !(builtins.hasAttr x e'));
|
||||
|
||||
bigdata = lib.imap0 (i: _: toString i) (lib.replicate 999999 null);
|
||||
in {
|
||||
old = subtractListsOld [ "123" "456" "789" ] bigdata;
|
||||
new = subtractListsNew [ "123" "456" "789" ] bigdata;
|
||||
}
|
||||
12
src/unique.nix
Normal file
12
src/unique.nix
Normal file
@@ -0,0 +1,12 @@
|
||||
lib:
|
||||
let
|
||||
uniqueOld = builtins.foldl' (acc: e: if builtins.elem e acc then acc else acc ++ [ e ]) [];
|
||||
# uniqueNew = xs: let
|
||||
# entries = lib.genAttrs xs (_: null);
|
||||
# in builtins.concatMap (x: if );
|
||||
|
||||
bigdataMostlyDuplicates = (lib.replicate 999999 null) ++ ["unique"];
|
||||
bigdataMostlyUnique = lib.imap0 (i: _: toString i) (lib.replicate 999999 null) ++ ["123" "456"];
|
||||
in {
|
||||
old = uniqueOld bigdataMostlyDuplicates;
|
||||
}
|
||||
Reference in New Issue
Block a user