mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-24 07:38:46 +00:00
Hash table
This commit is contained in:
parent
46dfd58bda
commit
149984f5c0
14 changed files with 258 additions and 21 deletions
|
|
@ -1,3 +1,10 @@
|
|||
public fun size (l) {
|
||||
case l of
|
||||
{} -> 0
|
||||
| _ : t -> 1 + size (t)
|
||||
esac
|
||||
}
|
||||
|
||||
public fun foldl (f, acc, l) {
|
||||
case l of
|
||||
{} -> acc
|
||||
|
|
@ -59,13 +66,13 @@ public fun find (f, l) {
|
|||
}
|
||||
|
||||
public fun flatten (l) {
|
||||
local res = [0, {}];
|
||||
local res = [0, {}], curr = [res];
|
||||
|
||||
fun append (x) {
|
||||
local new = {x};
|
||||
local new = x : {};
|
||||
|
||||
res [1] := new;
|
||||
res := new
|
||||
curr [0][1] := new;
|
||||
curr [0] := new
|
||||
}
|
||||
|
||||
iter (fun (x) {iter (append, x)}, l);
|
||||
|
|
@ -88,4 +95,18 @@ public fun unzip (a) {
|
|||
[aa, bb] -> [a : aa, b : bb]
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
public fun remove (f, l) {
|
||||
case l of
|
||||
{} -> {}
|
||||
| h : t -> if f (h) then t else h : remove (f, t) fi
|
||||
esac
|
||||
}
|
||||
|
||||
public fun filter (f, l) {
|
||||
case l of
|
||||
{} -> {}
|
||||
| h : t -> if f (h) then h : filter (f, t) else filter (f, t) fi
|
||||
esac
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue