diff --git a/bench/line_rope_svelte b/bench/line_rope_svelte deleted file mode 100755 index b623392..0000000 Binary files a/bench/line_rope_svelte and /dev/null differ diff --git a/src/gap_map.sml b/src/gap_map.sml new file mode 100644 index 0000000..17a8d2e --- /dev/null +++ b/src/gap_map.sml @@ -0,0 +1,52 @@ +signature GAP_MAP_PAIR = +sig + type key + type value + + val l: key * key -> bool + val eq: key * key -> bool + val g: key * key -> bool + + val maxNodeSize: int +end + +signature GAP_MAP = +sig + structure Fn: GAP_MAP_PAIR + + type t + + val empty: t + val isEmpty: t -> bool + + val add: Fn.key * Fn.value * t -> t + val remove: Fn.key * t -> t + + val get: Fn.key * t -> Fn.value option + val min: t -> (Fn.key * Fn.value) option + val max: t -> (Fn.key * Fn.value) option + + val moveToStart: t -> t + val moveToEnd: t -> t + val moveTo: Fn.key * t -> t +end + +functor MakeGapMap(Fn: GAP_MAP_PAIR): GAP_MAP = +struct + structure Fn = Fn + + type t = + { leftKeys: Fn.key vector list + , letVals: Fn.value vector list + , rightKeys: Fn.key vector list + , rightVals: Fn.value vector list + } + + val empty = {leftKeys = [], leftVals = [], rightKeys = [], rightVals = []} + + fun isEmpty {leftKeys = [], rightKeys = [], ...} = true + | isEmpty _ = false + + fun isLessThanTarget (v1, v2) = + Vector.length v1 + Vector.length v2 <= Fn.maxNodeSize +end diff --git a/src/gap_set.sml b/src/gap_set.sml index 99d3bd4..94ab607 100644 --- a/src/gap_set.sml +++ b/src/gap_set.sml @@ -18,6 +18,8 @@ sig val empty: t val isEmpty: t -> bool + val singleton: Fn.key -> t + val add: Fn.key * t -> t val remove: Fn.key * t -> t val removeMany: Fn.key * Fn.key * t -> t @@ -46,7 +48,7 @@ struct | isEmpty _ = false fun singleton x = - {left = [], right = Vector.fromList [x]} + {left = [], right = [Vector.fromList [x]]} fun isLessThanTarget (v1, v2) = Vector.length v1 + Vector.length v2 <= Fn.maxNodeSize