begin implementation of gap_map.sml
This commit is contained in:
Binary file not shown.
52
src/gap_map.sml
Normal file
52
src/gap_map.sml
Normal file
@@ -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
|
||||||
@@ -18,6 +18,8 @@ sig
|
|||||||
val empty: t
|
val empty: t
|
||||||
val isEmpty: t -> bool
|
val isEmpty: t -> bool
|
||||||
|
|
||||||
|
val singleton: Fn.key -> t
|
||||||
|
|
||||||
val add: Fn.key * t -> t
|
val add: Fn.key * t -> t
|
||||||
val remove: Fn.key * t -> t
|
val remove: Fn.key * t -> t
|
||||||
val removeMany: Fn.key * Fn.key * t -> t
|
val removeMany: Fn.key * Fn.key * t -> t
|
||||||
@@ -46,7 +48,7 @@ struct
|
|||||||
| isEmpty _ = false
|
| isEmpty _ = false
|
||||||
|
|
||||||
fun singleton x =
|
fun singleton x =
|
||||||
{left = [], right = Vector.fromList [x]}
|
{left = [], right = [Vector.fromList [x]]}
|
||||||
|
|
||||||
fun isLessThanTarget (v1, v2) =
|
fun isLessThanTarget (v1, v2) =
|
||||||
Vector.length v1 + Vector.length v2 <= Fn.maxNodeSize
|
Vector.length v1 + Vector.length v2 <= Fn.maxNodeSize
|
||||||
|
|||||||
Reference in New Issue
Block a user