sorting
本頁內容尚未翻譯。
python.SortPlaces
Section titled “python.SortPlaces”record SortPlacesThe places sorting uses: the list of pairs, its length, the indexes, the pivot, the operands and the truth of a comparison.
python.Sorting.at
Section titled “python.Sorting.at”def Sorting.at (s : Run) (p : Place) : NatThe natural number kept in the place p in the run s.
python.Sorting.index
Section titled “python.Sorting.index”def Sorting.index (p : Place) : Run -> NatThe natural number in the place p, read from the run.
python.Sorting.zero
Section titled “python.Sorting.zero”def Sorting.zero : Run -> NatZero, for any run.
python.Sorting.put
Section titled “python.Sorting.put”def Sorting.put (p : Place) (f : Run -> Nat) : CodeThe natural number f reads from the run, put in the place p.
python.Sorting.nth
Section titled “python.Sorting.nth”def Sorting.nth (xs : List Value) (k : Nat) : ValueThe value at the position k of the list xs (None past its end).
python.Sorting.keyOf
Section titled “python.Sorting.keyOf”def Sorting.keyOf (pair : Value) : ValueA pair’s key.
python.Sorting.itemOf
Section titled “python.Sorting.itemOf”def Sorting.itemOf (pair : Value) : ValueA pair’s item.
python.Sorting.pairAt
Section titled “python.Sorting.pairAt”def Sorting.pairAt (s : Run) (ps : SortPlaces) (k : Nat) : ValueThe pair at the position k in the run s, with the sorting places ps.
python.Sorting.key
Section titled “python.Sorting.key”def Sorting.key (s : Run) (ps : SortPlaces) (k : Nat) : ValueThe key of the pair at the position k in the run s, with the sorting places ps.
python.Sorting.change
Section titled “python.Sorting.change”def Sorting.change (node : String) (ps : SortPlaces) (f : Run -> List Value -> List Value) : CodeThe pairs (in the sorting places ps) changed by the function f of the run and them, at node.
python.Sorting.reversed
Section titled “python.Sorting.reversed”def Sorting.reversed (node : String) (ps : SortPlaces) (i : Run -> Nat) (j : Run -> Nat) : CodeThe pairs (in the sorting places ps) from the position i up to j reversed, at node.
python.Sorting.compared
Section titled “python.Sorting.compared”def Sorting.compared (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) (method : String) (reflected : String) (symbol : String) (x : Run -> Value) (y : Run -> Value) : CodeThe truth of the comparison x symbol y of keys read from the run (its method, the reflected one, the
built-in order), in the truth place of ps, at node with the program’s functions and their bodies.
python.Sorting.less
Section titled “python.Sorting.less”def Sorting.less (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) (x : Run -> Value) (y : Run -> Value) : CodeThe truth of x < y (the user’s __lt__, or the reflected __gt__), in the truth place of ps, at node with
the program’s functions and their bodies.
python.Sorting.greater
Section titled “python.Sorting.greater”def Sorting.greater (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) (x : Run -> Value) (y : Run -> Value) : CodeThe truth of x > y (the user’s __gt__, or the reflected __lt__), in the truth place of ps, at node with
the program’s functions and their bodies.
python.Sorting.up
Section titled “python.Sorting.up”def Sorting.up (p : Place) : CodeThe index place p one up.
python.Sorting.within
Section titled “python.Sorting.within”def Sorting.within (ps : SortPlaces) (s : Run) : Checked Stop BoolWhether n (in the sorting places ps) is before the end in the run s.
python.Sorting.next
Section titled “python.Sorting.next”def Sorting.next (ps : SortPlaces) (s : Run) : ValueThe key at n (in the sorting places ps) in the run s.
python.Sorting.previous
Section titled “python.Sorting.previous”def Sorting.previous (ps : SortPlaces) (s : Run) : ValueThe key before n (in the sorting places ps) in the run s.
python.Sorting.ascending
Section titled “python.Sorting.ascending”def Sorting.ascending (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) : Codecount_run’s ascending stretch from n (in the sorting places ps): while the next key is not less than the one
before; at node with the program’s functions and their bodies.
python.Sorting.lastEqual
Section titled “python.Sorting.lastEqual”def Sorting.lastEqual (node : String) (ps : SortPlaces) : CodeREVERSE_LAST_NEQ at node: the last stretch of equal keys (neq of the sorting places ps after the first)
reversed, neq back to 0.
python.Sorting.descending
Section titled “python.Sorting.descending”def Sorting.descending (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) : Codecount_run’s descending stretch from n (in the sorting places ps): a next key less than the one before ends a
stretch of equal keys; one greater ends the run; else it is equal to it. At node with the program’s functions
and their bodies.
python.Sorting.countRun
Section titled “python.Sorting.countRun”def Sorting.countRun (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) : Codecount_run: the length of the run at the start in run of the sorting places ps (a descending one reversed into
an ascending one); at node with the program’s functions and their bodies.
python.Sorting.binarySort
Section titled “python.Sorting.binarySort”def Sorting.binarySort (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) : Codebinarysort from ok of the sorting places ps (the run before it sorted): each next pair put where its key
belongs among those before it, found by halving (pivot < a[M]); at node with the program’s functions and their
bodies.
python.Sorting.sort
Section titled “python.Sorting.sort”def Sorting.sort (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) (backward : Run -> Bool) : CodeThe pairs in the sorting places ps sorted by their keys, as CPython’s listsort does for fewer than 64
(backward: reversed first and after, so equal keys keep their order); at node with the program’s functions and
their bodies.
python.Sorting.best
Section titled “python.Sorting.best”def Sorting.best (node : String) (functions : List Function) (bodies : Nat -> Code) (ps : SortPlaces) (isMax : Bool) : Codemin (the first least key: key < best) or max (isMax, the first greatest: key > best) of the pairs in
the sorting places ps (there is one at least): its position in run; at node with the program’s functions and
their bodies.
python.Sorting.names
Section titled “python.Sorting.names”def Sorting.names : List StringThe model’s own functions for sorting, after the program’s functions and the built-in generators in the table:
model sort (the pairs, whether reversed) sorts the list of pairs; model extreme (the pairs, whether max) returns the item
of the best key. Their statements are in the table once, not at every call; their frames do not count toward the
recursion limit (Function.internal).
python.Sorting.frame
Section titled “python.Sorting.frame”def Sorting.frame : SortPlacesThe kept places of a sorting frame: the two arguments first, then the places sorting uses, then a scratch slot.
python.Sorting.slots
Section titled “python.Sorting.slots”def Sorting.slots : NatHow many locals a sorting frame has.
python.Sorting.functions
Section titled “python.Sorting.functions”def Sorting.functions : List FunctionThe sorting functions as table entries.
python.Sorting.body
Section titled “python.Sorting.body”def Sorting.body (k : Nat) (functions : List Function) (bodies : Nat -> Code) : CodeThe body of the sorting function at the position k among them, with the program’s functions and their
bodies.
python.Sorting.called
Section titled “python.Sorting.called”def Sorting.called (node : String) (functions : List Function) (bodies : Nat -> Code) (name : String) (arguments : List Expression) (result : Place) : CodeA call of the sorting function name on the arguments at node, its result into the place result, with the
program’s functions and their bodies.
python.Sorting.paired
Section titled “python.Sorting.paired”def Sorting.paired (node : String) (keys : Place) (items : Place) (pairs : Place) : CodePairs of the keys and items in two lists (in places), into a new list in the place pairs, at node.
python.Sorting.itemsOf
Section titled “python.Sorting.itemsOf”def Sorting.itemsOf (s : Run) (pairs : Place) : List ValueThe items of the list of pairs in the place pairs in the run s, in order.
python.Sorting.user
Section titled “python.Sorting.user”def Sorting.user (s : Run) (keys : Place) : BoolWhether one of the keys (a list in a place) in the run s defines comparison methods (a user’s code compares
it).
python.Sorting.byKeys
Section titled “python.Sorting.byKeys”def Sorting.byKeys (node : String) (functions : List Function) (bodies : Nat -> Code) (pairs : Place) (items : Place) (keys : Place) (reversed : Option Place) (result : Place) : CodeThe items sorted by their keys (lists in places; the items themselves for no key function), reversed when
that place holds true, into a new list in result: by the user’s comparisons when a key defines them (model sort,
the pairs made in the place pairs), else the built-in’s. At node with the program’s functions and their
bodies.
python.Sorting.extremeByKeys
Section titled “python.Sorting.extremeByKeys”def Sorting.extremeByKeys (node : String) (functions : List Function) (bodies : Nat -> Code) (pairs : Place) (name : String) (items : Place) (keys : Place) (fallback : Option Place) (result : Place) : Codemin or max (the name) of the items by their keys (lists in places) into result: by the user’s
comparisons when a key defines them (model extreme, the pairs made in the place pairs; ValueError, or the
default in fallback, for none), else the built-in’s. At node with the program’s functions and their bodies.
python.Sorting.keyed
Section titled “python.Sorting.keyed”def Sorting.keyed (s : Run) (key : Option Place) : BoolWhether a key function was given in the run s (the place key, with a value that is not None).
python.Sorting.listSort
Section titled “python.Sorting.listSort”def Sorting.listSort (node : String) (functions : List Function) (bodies : Nat -> Code) (pairs : Place) (receiver : Place) (key : Option Place) (reversed : Option Place) (saved : Place) (keys : Place) (sorted : Place) (iterator : Place) (item : Place) (ended : Place) (trying : Place) (guard : Place) (flag : Place) (result : Place) : Codexs.sort(key=f, reverse=r) on the list in receiver, with key and reversed the places of f and r, as
CPython’s list.sort: the list empty while its keys are computed and it is sorted (Sorting.byKeys); ValueError
when the key function or a comparison changed it (the list then has the sorted items); after an exception the list
has its items in the order the sorting had left them. The keys are the items themselves without a key function. At
node with the program’s functions and their bodies; the places: saved the items copied out, keys their
keys, pairs the pairs, sorted the sorted items, iterator, item, ended and trying for computing the keys,
guard for the try around it, flag whether the list was changed, and result the None it returns.