Standard Container Library

http://www.zinnamturm.eu/downloadsAC.htm#Co_ http://sourceforge.net/projects/ta1/files/co2.0
Post Reply
Dmitry Dagaev
Posts: 68
Joined: Wed Mar 29, 2017 3:58 pm

Standard Container Library

Post by Dmitry Dagaev »

I'm going to introduce Scl - Standard Container Library. Scl package implements vectors, lists, queues, stacks, maps without any generics. It uses BlackBox Kernel metadata.

Motivation:
1. The same software for the same tasks like sorting or binary search of elements;
2. No generics infrastructure;
3. Simpler solutions as more effective, for example, the stl reference operator[]( size_type pos ) has more overhead.

P.S. (for administration) Stl toppic should be better placed in a separate location Components/Stl .
Dmitry Dagaev
Posts: 68
Joined: Wed Mar 29, 2017 3:58 pm

Re: Standard Container Library

Post by Dmitry Dagaev »

Example - Vectors.Vector

Code: Select all

MyRec = RECORD
   i1: INTEGER;
END;
MyVec = RECORD (Vectors.Vector)
   data*: POINTER TO ARRAY OF MyRec;
END;

Code: Select all

vec.Init(10);
Log.String("Pointer Initial Size,Capacity="); Log.Int(vec.size); Log.Int(vec.capacity); Log.Ln;
mr.i1 := 109; vec.Set(9, mr);
mr.i1 := 110; vec.Set(10, mr);
mr.i1 := 111; vec.Set(11, mr);
Log.String("Pointer To Vector Size,Capacity="); Log.Int(vec.size); Log.Int(vec.capacity); Log.Ln;
FOR j := 0 TO vec.size-1 DO
   Log.Int(j); Log.String(" ="); Log.Int(vec.data[j].i1); Log.Ln;
END;
Vector is resing to 12. Standard elements access vec.data[j] is preferable, than operator[] in c++ case.

From inside it must be mentioned, that vec.data is safely realloced to the new array of type MyRec, using Kernel metadata.
Dmitry Dagaev
Posts: 68
Joined: Wed Mar 29, 2017 3:58 pm

Re: Standard Container Library

Post by Dmitry Dagaev »

Example - - Lists.IndexedList

Code: Select all

SearchElem = RECORD (Lists.Elem)
   ri-: Keys.SString32Key;
   i1: INTEGER;
END;
SearchElemPArr = POINTER TO ARRAY OF SearchElem;
MySearchList = RECORD (Lists.IndexedList)
   data*: POINTER TO ARRAY OF SearchElemPArr;
END;
List, Queue, Deque, Stack operate with pointer to array of pointers - POINTER TO ARRAY OF %SearchElemPArr. Calling NEW for arrays is less time-consuming, so internal representation of Lists group uses arrays. Keys.SString32Key means string key for elements comparison. Elements comparison allows making step towards sorting and binary search.

Code: Select all

li.Init(params);
el.ri.name := "orange"; el.i1 := 2; li.PushBack(el);
el.ri.name := "red"; el.i1 := 1; li.PushFront(el);
el.ri.name := "yellow"; el.i1 := 3; li.Insert(Lists.iterNil, el);
el.ri.name := "green"; el.i1 := 4; li.PushBack(el);
el.ri.name := "lightblue"; el.i1 := 5; li.PushBack(el);
el.ri.name := "blue"; el.i1 := 6; li.PushBack(el);
li.Sort;
el.ri.name := "lightblue";
found := li.Find(el, it);
Log.String("lightblue Find="); Log.Bool(found); Log.Int(it.r);  Log.Int(it.c); Log.Ln
So custom lists, queues, stacks can be derived from.
Post Reply