GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing reasonml.github.io — Reason · Reason lets you write simple, fast and quality type safe code while leveraging both the JavaScript & OCaml ecosystems. Module ArrayLabelsmodule ArrayLabels: sig .. endArray operations. The labeled version of this module can be used as described in the
type 'a t = 'a array
An alias for the type of arrays. val length : 'a array -> int Return the length (number of elements) of the given array. val get : 'a array -> int -> 'a
val set : 'a array -> int -> 'a -> unit
val make : int -> 'a -> 'a array
val create_float : int -> float array
val init : int -> f:(int -> 'a) -> 'a array
val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
val append : 'a array -> 'a array -> 'a array
val concat : 'a array list -> 'a array Same as val sub : 'a array -> pos:int -> len:int -> 'a array
val copy : 'a array -> 'a array
val fill : 'a array -> pos:int -> len:int -> 'a -> unit
val blit : src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int -> len:int -> unit
val to_list : 'a array -> 'a list
val of_list : 'a list -> 'a array
Iteratorsval iter : f:('a -> unit) -> 'a array -> unit
val iteri : f:(int -> 'a -> unit) -> 'a array -> unit Same as val map : f:('a -> 'b) -> 'a array -> 'b array
val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b array Same as val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b array -> 'a
val fold_left_map : f:('a -> 'b -> 'a * 'c) -> init:'a -> 'b array -> 'a * 'c array
val fold_right : f:('b -> 'a -> 'a) -> 'b array -> init:'a -> 'a
Iterators on two arraysval iter2 : f:('a -> 'b -> unit) -> 'a array -> 'b array -> unit
val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array
Array scanningval for_all : f:('a -> bool) -> 'a array -> bool
val exists : f:('a -> bool) -> 'a array -> bool
val for_all2 : f:('a -> 'b -> bool) -> 'a array -> 'b array -> boolSame as
val exists2 : f:('a -> 'b -> bool) -> 'a array -> 'b array -> boolSame as
val mem : 'a -> set:'a array -> bool
val memq : 'a -> set:'a array -> bool Same as
val find_opt : f:('a -> bool) -> 'a array -> 'a option
val find_map : f:('a -> 'b option) -> 'a array -> 'b option
Arrays of pairsval split : ('a * 'b) array -> 'a array * 'b array
val combine : 'a array -> 'b array -> ('a * 'b) array
Sortingval sort : cmp:('a -> 'a -> int) -> 'a array -> unitSort an array in increasing order according to a comparison
function. The comparison function must return 0 if its arguments
compare as equal, a positive integer if the first is greater,
and a negative integer if the first is smaller (see below for a
complete specification). For example, The current implementation uses Heap Sort. It runs in constant stack space. Specification of the comparison function:
Let
When
val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unitSame as The current implementation uses Merge Sort. It uses a temporary array of
length val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unitSame as Arrays and Sequencesval to_seq : 'a array -> 'a Seq.t Iterate on the array, in increasing order. Modifications of the array during iteration will be reflected in the sequence.
val to_seqi : 'a array -> (int * 'a) Seq.t Iterate on the array, in increasing order, yielding indices along elements. Modifications of the array during iteration will be reflected in the sequence.
val of_seq : 'a Seq.t -> 'a array Create an array from the generator
Arrays and concurrency safetyCare must be taken when concurrently accessing arrays from multiple domains: accessing an array will never crash a program, but unsynchronized accesses might yield surprising (non-sequentially-consistent) results. AtomicityEvery array operation that accesses more than one array element is not atomic. This includes iteration, scanning, sorting, splitting and combining arrays. For example, consider the following program: let size = 100_000_000
let a = ArrayLabels.make size 1
let d1 = Domain.spawn (fun () ->
ArrayLabels.iteri ~f:(fun i x -> a.(i) <- x + 1) a
)
let d2 = Domain.spawn (fun () ->
ArrayLabels.iteri ~f:(fun i x -> a.(i) <- 2 * x + 1) a
)
let () = Domain.join d1; Domain.join d2
After executing this code, each field of the array Data racesIf two domains only access disjoint parts of the array, then the observed behaviour is the equivalent to some sequential interleaving of the operations from the two domains. A data race is said to occur when two domains access the same array element without synchronization and at least one of the accesses is a write. In the absence of data races, the observed behaviour is equivalent to some sequential interleaving of the operations from different domains. Whenever possible, data races should be avoided by using synchronization to mediate the accesses to the array elements. Indeed, in the presence of data races, programs will not crash but the observed behaviour may not be equivalent to any sequential interleaving of operations from different domains. Nevertheless, even in the presence of data races, a read operation will return the value of some prior write to that location (with a few exceptions for float arrays). Float arraysFloat arrays have two supplementary caveats in the presence of data races. First, the blit operation might copy an array byte-by-byte. Data races between such a blit operation and another operation might produce surprising values due to tearing: partial writes interleaved with other operations can create float values that would not exist with a sequential execution. For instance, at the end of let zeros = Array.make size 0.
let max_floats = Array.make size Float.max_float
let res = Array.copy zeros
let d1 = Domain.spawn (fun () -> Array.blit zeros 0 res 0 size)
let d2 = Domain.spawn (fun () -> Array.blit max_floats 0 res 0 size)
let () = Domain.join d1; Domain.join d2
the Second, on 32-bit architectures, getting or setting a field involves two separate memory accesses. In the presence of data races, the user may observe tearing on any operation. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |