<<<<<<<<<<<<<<<<<

multi_key_sort(prog_tools)Programming Toolsmulti_key_sort(prog_tools)

NAME

multi_key_sort - multi-key sort object

DESCRIPTION

The multi_key_sort object will perform multi-key sorts of an arbitrary number of vector and/or s_vector objects. All objects that it sorts must contain the same number of elements.

SUPERCLASS

object

INSTANCE VARIABLES

data is a list of vector and/or s_vector object names that will be sorted. The order in which object names appears in the list determines the sorting order. The first object will be the primary key, the second will be the secondary key, and so on. range is a two-element vector that determines a subrange of the data to sort. The default value of (0,0) causes the entire data to be sorted.

MESSAGES

sort! sorts the data. Note that the contents of the data objects are modified. New ones are not created.

EXAMPLE

The following example allows the user to generate randomly placed labels in a bulletin board, then sort them using y as the primary key, x as the secondary key, and the label names as the tertiary key.

<motifinit

motif application=`SortDemo' create! ;

motif_form new: `f' parent=`motif' create! ;

motif_bulletin_board new: `bb' parent=`f' @ `topAttachment' : XmATTACH_FORM @ `leftAttachment' : XmATTACH_FORM @ `rightAttachment' : XmATTACH_FORM @ `width' : 384 @ `height' : 384 create! ;

motif_push_button new: `pb1' parent=`f' @ `topAttachment' : XmATTACH_WIDGET @ `topWidget' : [bb id?] @ `bottomAttachment' : XmATTACH_FORM @ `leftAttachment' : XmATTACH_FORM @ `rightAttachment' : XmATTACH_POSITION @ `rightPosition' : 50 @ `labelString' : `Push to generate labels' activate_action=`generate_labels' create! ;

actions new: `generate_labels' tick_actions=` scalar new: `x' new: `y';

loop new: `l' resolution= 1 duration= 4 tick_actions=` x drand48! * 300 integerize!; y drand48! * 300 integerize!; motif_label_gadget new! generate_name! parent=`bb' @ `x' : x @ `y' : y create! ; ' end_actions=` bb @ `width' : 384 @ `height' : 384; ' start! ; ' ;

motif_push_button new: `pb2' parent=`f' @ `topAttachment' : XmATTACH_WIDGET @ `topWidget' : [bb id?] @ `leftAttachment' : XmATTACH_WIDGET @ `leftWidget' : [pb1 id?] @ `rightAttachment' : XmATTACH_FORM @ `labelString' : `Push to sort labels' activate_action=`sort_labels' create! ;

actions new: `sort_labels' tick_actions=` collection new: `c' members=[motif_label_gadget instances?];

-- parser parse: `! Data before sorting:'; s_vector new: `names' = [c members?] /* print:`components' */; vector new: `x' = [c @ `x' scalar_value?] /* print:`components' */; vector new: `y' = [c @ `y' scalar_value?] /* print:`components' */; multi_key_sort new: `sorter' data=(`y', `x', `names') sort! ; -- parser parse: `! Data after sorting:'; -- names print:`components'; -- x print:`components'; -- y print:`components'; ' ;

motif on! start!;

SEE ALSO

vector, s_vector, sorted_collection


Please send comments and suggestions to
consult@rpi.edu