Sort disjoint sublist: Difference between revisions

Line 576:
let
typedef index = [i : nat | i < m] int i
 
val p_values = addr@ values
 
prval () = lemma_list_vt_param values
Line 594 ⟶ 592:
val () = array_quicksort<index> (ix, num_indices)
 
(* Initialize thea "refs" array with pointers to the relevant list
nodes. The pointers will be in ascending index order. *)
val @(pf_refs, pfgc_refs | p_refs) =
array_ptr_alloc<ptr> num_indices
infun
macdef refs = !p_refs
init_refs {j : nat | j <= m}
 
{i : nat | i <= n}
(* Initialize the "refs" array with pointers to the relevant list
nodes. The pointers will be in ascending index{p_refs order.: *)addr}
.<m - j>.
implement
(pf_refs : !array_v (ptr?, p_refs + (i * sizeof ptr),
array_initize$init<ptr> (i, x) =
n - i)
let
val @(pf1, fpf1 | p1) = $UN.ptr_vtake{list_vt >> array_v (aptr, m)}p_refs p_values+ (i * sizeof ptr),
val i1 = g1ofg0 n - i) |
ix : &array (index, n),
prval () = lemma_g1uint_param i1
val () = assertloc (i1 < num_indices) p_refs : ptr p_refs,
i : size_t i,
val @(pf2, fpf2 | p2) = $UN.ptr_vtake{@[index][n]} p_ix
macdef ix = !p_ix values : &list_vt (a, m - j),
val () = x j := size_t j)
:<!wrt> void =
$UN.castvwtp0{ptr} (list_vt_getref_at (!p1, ix[i1]))
if i prval< ()num_indices = fpf2 pf2then
prvalcase+ ()values = fpf1 pf1of
| list_vt_nil () => $effmask_exn assertloc (false)
in
| @ list_vt_cons (head, tail) =>
end
if j = ix[i] then
val () = array_initize<ptr> (refs, num_indices)
let
prval @(pf_elem, pf_rest) = array_v_uncons pf_refs
val p = ptr_add<ptr> (p_refs, i)
val () = ptr_set<ptr> (pf_elem | p, addr@ values)
val () = init_refs (pf_rest | ix, p_refs, succ i,
tail, succ j)
prval () = pf_refs := array_v_cons (pf_elem, pf_rest)
prval () = fold@ values
in
end
else
let
val () = init_refs (pf_refs | ix, p_refs, i,
tail, succ j)
prval () = fold@ values
in
end
else
let
prval () = pf_refs := array_v_unnil_nil{ptr?, ptr} pf_refs
in
end
val () = init_refs (pf_refs | ix, p_refs, i2sz 0, values, i2sz 0)
 
(* Sort through the "refs" pointers. Here we will do that by
Line 647 ⟶ 670:
fun
write_back_values
{i : nat | i <= n}
(refs{p_refs : &array (ptr, n),addr}
vals(pf_refs : &array!array_v (aptr, p_refs, n), |
i p_refs : size_tptr i)p_refs,
vals : &array (a, n),
i : size_t i)
: void =
if i <> num_indices then
let
macdef refs = !p_refs
val @(pf1, fpf1 | p1) = $UN.ptr_vtake{List1_vt a} (refs[i])
val+ @ list_vt_cons (head, tail) = !p1
Line 660 ⟶ 686:
prval () = fpf1 pf1
in
write_back_values (refspf_refs | p_refs, vals, succ i)
end
val () = write_back_values (refspf_refs | p_refs, vals, i2sz 0)
in
array_ptr_free (pf_ix, pfgc_ix | p_ix);
1,448

edits