VI Collections

“——————————————————————————————————————————————————



Support translation: http://amzn.to/1Z7d5oc
——————————————————————————————————————————————————
VI Collections
Collection: Dynamic array which can store heterogeneous objects and in contrast to classical array, the size reflects size of actual no of objects rather than declared.
E,g,
MyCall {array} 0 circle 1 line 2 “Hello World” ..Index
Note: Objects can be accessed by index as with classical array.
Size of collection reflects actual size of for above objects (by appreciating object 37.5, the collection expand by corresponding number of bytes).
No dimensioning (size varies) – i.e. no declaration.
Support of Collection Classes
Objects.TPU – Standard Pascal Module
Basic Features Of Collections
Assume VAR Mycoll : Tcollection;
{and mycoll constructed and inialised}
1 Append Object
2 Return Object at position 2:

Mycoll.Insert(PAnyObject) ← pointer to constructor object
PAnyObj := Mycoll.AT(2);
3. Overwrite object at 1 by object at 2:
Mycoll.ATPUT(1, PAnyObj)
Size decreases(obj at 2 is smaller than original object at 1)

4. Insert Object at POS 1 (i.e. In front of) Mycoll.ATINSERT(1,PNewObj)
Size increases Objects after original 1 are Renumbered (e.g. obj with index 1 is now with index 2)
↑
REM: The same applies with deletion operation.
VI.1 Unsorted Collections
6 T7-9 Serve as manual – (have just overview of methods do not study details) 7 Page 9 shows some important algorithms
VI.2 Sorted Collections
8 Subclasses of Tsorted Collection class 9 NEW object is inserted automatically into correct position keeping the order. 10 Programmer can choose key data field (as sort criteria) himself (And
Ascending / Descending order as well). 11 TSortedCollection overrides Tcollection.Insert() method (i.e. it really inserts rather than appends).
A) Determination of a Key field
Programmer can choose any class field as a key field, used as a criteria or sorted. This is done by overriding
Function KeyOf (PItem : Pointer) : Pointer; Virtual;
E.g. to choose a name in obj class (referenced on T10-11) The body will be
KeyOf := Pobj(PItem)^.Name;
PObj = Pointer to the var class (upmost descriptor) Name = name of field used as key field.
B) Determination of Order (Asc / Desc)
User is to override function compare (Pkey1. Pkey2 : Pointer) : Integer; Virtual; This function is called TSorted collection.Insert() method to compare key data field determined by function Keyof with those on the collection to find correct Insert position corresponding to the chosen order.
E.g. To sort in ascending order of names
Body of compare()
If str_20(PKey) > str_20(PKey2) then compare := +1;

= := 0; < := -1;
str_20 = data type cast
(Name vars declared as str_20)
Rem: to change the order to descending order just swap <>
Searching
Method TSortedCollection.search() makes use of a key field defined by KeyOf() to find the object. The key value passed as an argument must be specified as a pointer to it!!
E.g. to search for ‘Gatt’ Key := ‘Gatt’;
If MysortColl.search(@ key, pos) Then… @ = pointer Object of TSorted Collection class Returns true and the object position (pos) where found or false and the position where
the object might be inserted if not found. Manual of TSorted collection services T10-11

“——————————————————————————————————————————————————

Appoġġ traduzzjoni: http://amzn.to/1Z7d5oc
——————————————————————————————————————————————————
VI Kollezzjonijiet
Ġbir: firxa Dynamic li jista ‘jaħżen oġġetti eteroġeni u b’kuntrast ma’ firxa klassika, id-daqs jirrifletti d-daqs tal-ebda attwali ta ‘oġġetti aktar milli iddikjarat.
E, g,
MyCall {firxa} 0 ċirku linja 1 2 â € œHello Worldâ € ..Index
Nota: Oġġetti jistgħu jiġu aċċessati permezz indiċi mal firxa klassika.
Daqs tal-ġbir jirrifletti d-daqs reali tal għal oġġetti ta ‘hawn fuq (minn japprezza għan 37.5, il-ġbir jespandu bin-numru ta’ bytes korrispondenti).
Nru dimensjonar (daqs tvarja) â € “”jiġifieri l-ebda dikjarazzjoni.
Appoġġ tal-Klassijiet Ġbir
Objects.TPU â € “”Standard Pascal Modulu
Karatteristiċi bażiċi ta ‘Kollezzjonijiet
Assumi VAR Mycoll: Tcollection;
{U mycoll mibnija u inialised}
1 Ehmeż Għan
Għan 2 Ritorn fil-pożizzjoni 2:

Mycoll.Insert (PAnyObject) â † pointer li oġġett kostruttur
PAnyObj: = Mycoll.AT (2);
3. jissostitwixxu oġġett ta ‘1 minħabba l-għan ta’ 2:
Mycoll.ATPUT (1, PAnyObj)
Daqs tnaqqis (obj f’2 huwa iżgħar minn oġġett oriġinali fl-1)

4. Daħħal Għan fl-POS 1 (jiġifieri Quddiem) Mycoll.ATINSERT (1, PNewObj)
daqs żidiet Objects wara oriġinali 1 qed jingħataw numri ġodda (eż obj b’indiċi 1 issa hija b’indiċi 2)
â † “”
REM: L-istess japplika ma ‘operazzjoni tħassir.
Kollezzjonijiet VI.1 ta ‘ħut imħallat
6 T7-9 Iservi bħala manwal â € “”(għadek ħarsa ġenerali tal-metodi ma ‘studju dettalji) 7 Page 9 turi xi algoritmi importanti
Kollezzjonijiet VI.2 sseparati
8 subklassijiet ta Tsorted Ġbir klassi 9 oġġett ġdid jiddaħħal awtomatikament fil-pożizzjoni korretta żamma tal-ordni. 10 Programmer jistgħu jagħżlu kaxxa tad-data ewlenija (bħala kriterji sort) innifsu (U
Axxendenti / Dixxendenti ordni kif ukoll). 11 TSortedCollection tirbaħ fuq Tcollection.Insert () metodu (jiġifieri huwa verament idaħħal iktar milli tannetti).
A) Determinazzjoni ta ‘kamp Ewlenin
Programmer tista ‘tagħżel kwalunkwe tal-klassi bħala qasam ewlieni, użat bħala kriterji jew magħżula. Dan isir billi prevalenti
Funzjoni KeyOf (PItem: Pointer): Pointer; virtwali;
Eż biex tagħżel isem fil-klassi obj (referenzat fit T10-11) Il-korp se jkun
KeyOf: = Pobj (PItem) ^ Isem;.
PObj = Pointer għall-klassi var (deskrittur assoluta) Isem = isem tal-qasam użat bħala qasam ewlieni.
B) Id-determinazzjoni tal-Ordni (ASC / desc)
Utent huwa li jwarrab funzjoni iqabblu (Pkey1 Pkey2: Pointer.): Integer; virtwali; Din il-funzjoni tissejjaħ TSorted collection.Insert () metodu li tqabbel kaxxa tad-data ewlenija determinat mill-funzjoni Keyof ma ‘dawk fuq il-ġbir biex isibu Daħħal pożizzjoni korretta tikkorrispondi għall-ordni magħżula.
Eż Biex issolvi f’ordni axxendenti ta ‘ismijiet
Korp ta iqabblu ()
Jekk str_20 (PKey)> str_20 (PKey2) imbagħad iqabblu: = 1;

=: = 0; <: = -1;
str_20 =-tip mitfugħa data
(Isem vars dikjarat bħala str_20)
Rem: li tinbidel l-ordni biex ordni dixxendenti biss tpartit <>
tiftix
Metodu TSortedCollection.search () tagħmel użu ta ‘qasam primarju definit mill KeyOf () biex isibu l-oġġett. Il-valur ewlieni għadda bħala argument iridu jingħataw bħala indikatur li it !!
Eż ta ‘tiftix għal € ~Gattâ € ™ Ewlenin: = â € ~Gattâ € ™;
Jekk MysortColl.search (@ prinċipali, pos) Thenâ € | @ = Għan pointer ta ‘klassi TSorted Ġbir Denunzji vera u l-pożizzjoni oġġett (pos) fejn jinstabu jew falza u l-pożizzjoni fejn
l-oġġett jista ‘jkun miżjud, jekk ma tinstabx. Manwal tas TSorted servizzi ta ‘ġbir T10-11

“——————————————————————————————————————————————————