Module Tools (.ml)


module Tools: sig .. end
general functions


Modules


module IntTable: Hashtbl.S  with type key = int
a specialized Hashtbl with ints as keys.
module StringTable: Hashtbl.S  with type key = string
a specialized Hashtbl with strings as keys.

List


val list_remove_first : ('a -> bool) -> 'a list -> 'a list
list_remove_first predicate list returns list without the first element meeting the predicate. returns the original list if no element meets the condition.
val lists_unordered_equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
lists_unordered_equal equal list1 list2. are list1 and list2 identical with respect to equal if the order of the elements is not taken into account?
val lists_equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
are the two lists equal? That is, they are of same length and elements at the same element are equal with respect to the given comparison predicate.
val lists_merge : ('a -> 'a -> bool) -> 'a list -> 'a list -> 'a list
merges the two lists. assumes that each list contains no duplicates in itsels.
val list_add : ('a -> 'a -> bool) -> 'a list -> 'a -> 'a list
list_add equal list element adds element to list if it is not already contained.
val list_first : int -> 'a list -> 'a list
returns the first n elements of the list, or all, if the lists is shorter than n
val do_lists_intersect : ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
lists_shared equal list1 list2. do list1 and list2 have at least one element in common?
val lists_shared : ('a -> 'a -> bool) -> 'a list list -> 'a list
lists_shared equal lists finds all elements which are in more than one list.
val list_map : ('a -> 'a) -> 'a list -> 'a list
mapping of a list to the same type of list. if the list elements are immutable, and elements are mapped to themselves, then the tail of the original list can be reused as long as possible. not tail-resursive.
val mapping_extend : ('a * 'b) list ->
('a -> 'a -> bool) -> ('b -> 'b -> bool) -> 'a -> 'b -> ('a * 'b) list
mapping_extend mapping key_equal value_equal key value. mapping is considered to be a bijective mapping from keys to values. mapping_extend tries to extend mapping by the mapping key -> value. If key -> value is already part of mapping, mapping remains unchanged.
Raises Exit on failure, i.e. when there is an x so that key -> x or x -> value are already in mapping.

Array


val array_iter2 : ('a -> 'b -> unit) -> 'a array -> 'b array -> unit
array_iter2 f array1 array2 like List.iter2 for arrays.
Raises Exit if array1 and array2 are of different length.
val array_fold2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
array_fold2 f init array1 array2 like List.fold_left2 for arrays.
Raises Exit if array1 and array2 are of different length.
val array_exists : ('a -> bool) -> 'a array -> bool
like List.exists for an array.
val array_for_all : ('a -> bool) -> 'a array -> bool
like List.for_all for an array.
val array_find : ('a -> bool) -> 'a array -> 'a
like List.find for an array.
val array_for_all2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> bool
like List.for_all2 for an array.

Comparison



Specific integer comparison functions to avoid the call to the corresponding slower polymorphic functions.
val compare_int : int -> int -> int
Pervasives.compare specialized for integers.
val max_int : int -> int -> int
Pervasives.max specialized for integers.
val find_max : ('a -> 'a -> int) -> 'a list -> 'a
finds the maximum list element according to the given comparision function.
Raises Not_found on empty list.