VI Collections

 —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  — —











Sup­port trans­la­tion: http://amzn.to/1Z7d5oc
 — —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  — —
VI Col­lec­tions
Col­lec­tion: Dynam­ic array which can store het­ero­gen­eous objects and in con­trast to clas­sic­al array, the size reflects size of actu­al no of objects rather than declared.
E,g,
MyC­all {array} 0 circle 1 line 2 â€œHello World” ..Index
Note: Objects can be accessed by index as with clas­sic­al array.
Size of col­lec­tion reflects actu­al size of for above objects (by appre­ci­at­ing object 37.5, the col­lec­tion expand by cor­res­pond­ing num­ber of bytes).
No dimen­sion­ing (size var­ies) – i.e. no declar­a­tion.
Sup­port of Col­lec­tion Classes
Objects.TPU – Stand­ard Pas­cal Mod­ule
Basic Fea­tures Of Col­lec­tions
Assume VAR Mycoll : Tcol­lec­tion;
{and mycoll con­struc­ted and ini­al­ised}
1 Append Object
2 Return Object at pos­i­tion 2:

Mycoll.Insert(PAnyObject) ← point­er to con­struct­or object
PAnyObj := Mycoll.AT(2);
3. Over­write object at 1 by object at 2:
Mycoll.ATPUT(1, PAnyObj)
Size decreases(obj at 2 is smal­ler than ori­gin­al object at 1)

4. Insert Object at POS 1 (i.e. In front of) Mycoll.ATINSERT(1,PNewObj)
Size increases Objects after ori­gin­al 1 are Renumbered (e.g. obj with index 1 is now with index 2)
↑
REM: The same applies with dele­tion oper­a­tion.
VI.1 Unsor­ted Col­lec­tions
6 T7-9 Serve as manu­al – (have just over­view of meth­ods do not study details) 7 Page 9 shows some import­ant algorithms
VI.2 Sor­ted Col­lec­tions
8 Sub­classes of Tsor­ted Col­lec­tion class 9 NEW object is inser­ted auto­mat­ic­ally into cor­rect pos­i­tion keep­ing the order. 10 Pro­gram­mer can choose key data field (as sort cri­ter­ia) him­self (And
Ascend­ing / Des­cend­ing order as well). 11 TSor­ted­Col­lec­tion over­rides Tcollection.Insert() meth­od (i.e. it really inserts rather than appends).
A) Determ­in­a­tion of a Key field
Pro­gram­mer can choose any class field as a key field, used as a cri­ter­ia or sor­ted. This is done by over­rid­ing
Func­tion Key­Of (PItem : Point­er) : Point­er; Vir­tu­al;
E.g. to choose a name in obj class (ref­er­enced on T10-11) The body will be
Key­Of := Pobj(PItem)^.Name;
PObj = Point­er to the var class (upmost descriptor) Name = name of field used as key field.
B) Determ­in­a­tion of Order (Asc / Desc)
User is to over­ride func­tion com­pare (Pkey1. Pkey2 : Point­er) : Integer; Vir­tu­al; This func­tion is called TSor­ted collection.Insert() meth­od to com­pare key data field determ­ined by func­tion Key­of with those on the col­lec­tion to find cor­rect Insert pos­i­tion cor­res­pond­ing to the chosen order.
E.g. To sort in ascend­ing order of names
Body of com­pare()
If str_20(PKey) > str_20(PKey2) then com­pare := +1;

= := 0; < := -1;
str_20 = data type cast
(Name vars declared as str_20)
Rem: to change the order to des­cend­ing order just swap <>
Search­ing
Meth­od TSortedCollection.search() makes use of a key field defined by Key­Of() to find the object. The key value passed as an argu­ment must be spe­cified as a point­er to it!!
E.g. to search for ‘Gatt’ Key := ‘Gatt’;
If MysortColl.search(@ key, pos) Then… @ = point­er Object of TSor­ted Col­lec­tion class Returns true and the object pos­i­tion (pos) where found or false and the pos­i­tion where
the object might be inser­ted if not found. Manu­al of TSor­ted col­lec­tion ser­vices T10-11

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

Appoġġ traduzz­joni: http://amzn.to/1Z7d5oc
 — —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  — —
VI Kollezz­jon­iji­et
Ġbir: firxa Dynam­ic li jista jaħżen oġġet­ti eteroġeni u b’kuntrast ma’ firxa klassika, id-daqs jir­rif­let­ti d-daqs tal-ebda attwali ta oġġet­ti aktar mil­li iddikjar­at.
E, g,
MyC­all {firxa} 0 ċirku lin­ja 1 2 â € œHel­lo Worldâ € ..Index
Nota: Oġġet­ti jist­għu jiġu aċċes­sa­ti per­mezz indiċi mal firxa klassika.
Daqs tal-ġbir jir­rif­let­ti d-daqs reali tal għal oġġet­ti ta hawn fuq (minn jap­prezza għan 37.5, il-ġbir jespan­du bin-num­ru ta’ bytes kor­rispond­enti).
Nru dimens­jon­ar (daqs tvar­ja) â € ““jiġi­fieri l-ebda dikjarazz­joni.
Appoġġ tal-Klassiji­et Ġbir
Objects.TPU â € ““Stand­ard Pas­cal Mod­u­lu
Kar­at­ter­istiċi bażiċi ta Kollezz­jon­iji­et
Assumi VAR Mycoll: Tcol­lec­tion;
{U mycoll mib­n­i­ja u ini­al­ised}
1 Ehmeż Għan
Għan 2 Ritorn fil-pożizz­joni 2:

Mycoll.Insert (PAnyOb­ject) â † point­er li oġġett kostrut­tur
PAnyObj: = Mycoll.AT (2);
3. jis­sostitwixxu oġġett ta ‘1 minħab­ba l-għan ta’ 2:
Mycoll.ATPUT (1, PAnyObj)
Daqs tnaqqis (obj f’2 huwa iżgħar minn oġġett oriġin­ali fl-1)

4. Daħħal Għan fl-POS 1 (jiġi­fieri Qud­diem) Mycoll.ATINSERT (1, PNe­wObj)
daqs żidi­et Objects wara oriġin­ali 1 qed jingħataw num­ri ġod­da (eż obj b’indiċi 1 issa hija b’indiċi 2)
â † “”
REM: L-istess jap­p­lika ma operazz­joni tħassir.
Kollezz­jon­iji­et VI.1 ta ħut imħal­lat
6 T7-9 Iser­vi bħala man­wal â € “”(għadek ħarsa ġen­er­ali tal-met­odi ma stud­ju dettalji) 7 Page 9 turi xi algor­it­mi import­anti
Kollezz­jon­iji­et VI.2 ssep­ar­ati
8 sub­klassiji­et ta Tsor­ted Ġbir klassi 9 oġġett ġdid jid­daħħal awto­matika­ment fil-pożizz­joni kor­retta żam­ma tal-ord­ni. 10 Pro­gram­mer jist­għu jagħżlu kaxxa tad-data ewlen­i­ja (bħala kriterji sort) innif­su (U
Axxendenti / Dixxendenti ord­ni kif ukoll). 11 TSor­ted­Col­lec­tion tirbaħ fuq Tcollection.Insert () met­odu (jiġi­fieri huwa vera­ment idaħħal iktar mil­li tan­net­ti).
A) Determ­inazz­joni ta kamp Ewlen­in
Pro­gram­mer tista tagħżel kwalunk­we tal-klassi bħala qasam ewli­eni, użat bħala kriterji jew magħżu­la. Dan isir bil­li pre­val­enti
Fun­z­joni Key­Of (PItem: Point­er): Point­er; virt­wali;
Eż biex tagħżel isem fil-klassi obj (ref­er­en­zat fit T10-11) Il-korp se jkun
Key­Of: = Pobj (PItem) ^ Isem;.
PObj = Point­er għall-klassi var (deskrit­tur assol­uta) Isem = isem tal-qasam użat bħala qasam ewli­eni.
B) Id-determ­inazz­joni tal-Ord­ni (ASC / desc)
Utent huwa li jwar­rab fun­z­joni iqabblu (Pkey1 Pkey2: Point­er.): Integer; virt­wali; Din il-fun­z­joni tis­se­j­jaħ TSor­ted collection.Insert () met­odu li tqab­bel kaxxa tad-data ewlen­i­ja determ­in­at mill-fun­z­joni Key­of ma dawk fuq il-ġbir biex isibu Daħħal pożizz­joni kor­retta tikkor­rispondi għall-ord­ni magħżu­la.
Eż Biex issolvi f’ordni axxendenti ta ismiji­et
Korp ta iqabblu ()
Jekk str_20 (PKey)> str_20 (PKey2) imbagħad iqabblu: = 1;

=: = 0; <: = -1;
str_20 =-tip mit­fugħa data
(Isem vars dikjar­at bħala str_20)
Rem: li tin­bidel l-ord­ni biex ord­ni dixxendenti biss tpartit <>
tiftix
Met­odu TSortedCollection.search () tagħmel użu ta qasam primar­ju defin­it mill Key­Of () biex isibu l-oġġett. Il-valur ewli­eni għad­da bħala argu­ment iridu jingħataw bħala indikatur li it !!
Eż ta tiftix għal € ~Gat­tâ € ™ Ewlen­in: = â € ~Gat­tâ € ™;
Jekk MysortColl.search (@ prinċip­ali, pos) Thenâ € | @ = Għan point­er ta klassi TSor­ted Ġbir Denun­zji vera u l-pożizz­joni oġġett (pos) fejn jin­stabu jew falza u l-pożizz­joni fejn
l-oġġett jista jkun miżjud, jekk ma tin­stabx. Man­wal tas TSor­ted ser­vizzi ta ġbir T10-11

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