A group of data is called a collection. These collections can be grouped in different ways:
  • arrays, which define lists of indexed objects.
  • maps, which define pairs of values and keys.
  • virtual tables, which emulate databases in memory.
 

1 Arrays

Arrays are ordered by data sequences and classified by different types. They can have duplicates and nulls. They automatically fit to the data size of the list.

Each array has its own capacity. The capacity is the size of the array which is used to stock the elements of the list. Its size is always equal to or greater than the elements on the list. When all elements are added to the list, its capacity increases automatically.

XSQL routines have a set of operations for the creation and handling of arrays, which are encompassed with an array tag.

XSQL follows Java conventions. The first element of an array is the 0 index.
 

1.1 Basic Operations of an Array

Basic operations include insertion, deletion, indexed access and traversal of array elements.

 

1.1.1 Creation of an Array

Arrays are created via an array tag. An array can be assigned to a variable at the moment of creation, or passed to a function.

An empty array which assigns the q1 variable is created.

Copy
<xsql-script>
    <body>
        <set name='q1'>
            <array>/>
        </set>
        <println><q1/></println>
    </body>
</xsql-script>
 

An array with strings that assigns the q2 variable is created.

Copy
<xsql-script>
    <body>
        <set name='q2'>
            <array>
                <string>Mayo</string>
                <string>Junio</string>
                <string>Julio</string>
                <string>Agosto</string>
            </array>
        </set>
        <println><q2/></println>
    </body>
</xsql-script>
Mayo
Junio
Julio
Agosto
 

1.1.2 Array Data Insertion

In order to insert data into the array, which is identified by the q1 variable:

Copy
<xsql-script>
    <body>
        
        <!-- create an empty array -->
        <set name='q1'>
            <array />
        </set>
        
        <!-- Add one element -->
        <array.add name='q1'>
            <string>Enero</string>
        </array.add>
        
        <!-- Add three elements -->
        <array.add name='q1'>
            <string>Febrero</string>
            <string>Marzo</string>
            <string>Abril</string>
        </array.add>
        
        <println><q1/></println>
    </body>
</xsql-script>
Enero
Febrero
Marzo
Abril
 

1.1.3 Array Data Deletion

To delete the third element (April) of the array, which is identified by the q1 variable:

Copy
<println>
    <array.remove name='q1'>
        <number>3</number>
    </array.remove>
</println>
Abril
 

1.1.4 Indexed Access

To access the array, which is identified by the b variable: .

Copy
<println>
    <array.get name='q1'>
        <number>0</number>
    </array.get>
</println>
Enero
 

1.2 Other Array Operations

Other array operations include traversing, searching elements by value, emptying or copying/cloning.

 

1.2.1 Iterative Traversal

Can be used as an iterator in order to obtain an element of the array sequence.

Copy
<xsql-script>
    <body>
        <set name='q1'>
            <array>
            <string>Enero</string>
            <string>Febrero</string>
            <string>Marzo</string>
            <string>Abril</string>
            </array>
        </set>

        <iterator name='item'>
            <in>
                <q1/>
            </in>
            <do>
                <println>Elemento: <item /></println>
            </do>
        </iterator>

    </body>
</xsql-script>
Elemento: Enero
Elemento: Febrero
Elemento: Marzo
Elemento: Abril
 

1.2.2 Procedure While Elements Exist

An expression can be used to evaluate size while elements are being deleted.

Copy
<xsql-script>
    <body>
        <set name='q1'>
            <array>
            <string>Enero</string>
            <string>Febrero</string>
            <string>Marzo</string>
            <string>Abril</string>
            </array>
        </set>

        <while>
            <expr>
                <array.size><q1/></array.size>
            </expr>
            <do>
                <println>Eliminado: <array.removeFirst><q1/></array.removeFirst></println>
            </do>
        </while>
    </body>
</xsql-script>
Eliminado: Enero
Eliminado: Febrero
Eliminado: Marzo
Eliminado: Abril
 

1.2.3 Search

Can be used to search elements of the array.

Copy
<xsql-script>
    <body>
        <set name='q1'>
            <array>
            <string>Enero</string>
            <string>Febrero</string>
            <string>Marzo</string>
            <string>Abril</string>
            </array>
        </set>

        <println>
            <array.indexOf name='q1'>Marzo</array.indexOf>
        </println>
    </body>
</xsql-script>
2
 

1.2.4 Empty

To delete all objects in an array.

Copy
<array.clear name='q1' />
 

1.2.5 Cloning

The cloning operation makes it possible to produce a copy of the array. In the example, the array is cloned and stocked on q1_temp. After that, the operation will be in q1 and q1_temp, two identical arrays.

Copy
<set name='q1_temp'>
   <array.clone name='q1' />
</set>
 

1.3 Multidimensional Arrays

XSQL array scripts are one-dimensional, meaning that each array element contains only one object. Nevertheless, the object can be a data set or a structure. We will see later that the structure concept is very similar to C language structures. It is also possible to emulate multidimensional arrays through the creation of new data types, using structure declarations.

 

2 Maps

A hash table, associated matrix, hash map, dispersion table or fragmented table is a data structure which is associated with keys and values. The main operation which effectively supports this is the search: it allows access to the elements (telephone number and address, for example) stored through a generated key (by using name or account number, for example). It works by transforming the key with a hash function into a hash, a number which identifies the position (bucket or slot) where the hash table locates the desired value.

 

3 Basic Operations of a Map

 

3.1 Creation of a Map

All maps are declared via the map tag and they have pairs of included elements on the item tag.

Copy
<xsql-script>
    <body>
        <set name='m1'>
            <map>
                <item><string>RAQUET</string><number>10</number></item>
                <item><string>BALL</string><number>100</number></item>
            </map>
        </set>

        <println>
            <m1 />
        </println>
    </body>
</xsql-script>
{BALL=100, RAQUET=10}
 

3.2 Insertion of Key-Value on a Map

To insert an entry on a map, two values must be included. The item tag is not necessary, as it is a single entry.

Copy
<xsql-script>
    <body>
        <set name='m1'>
            <map>
                <item><string>RAQUET</string><number>10</number></item>
                <item><string>BALL</string><number>100</number></item>
            </map>
        </set>

        <!-- Add an item to previous declared map -->
        
        <map.put name='m1'>
            <string>PEN</string><number>25</number>
        </map.put>

        <println>
            <m1 />
        </println>
    </body>
</xsql-script>
{BALL=100, RAQUET=10, PEN=25}
 

3.3 Deleting an Entry

To delete an entry, the user must specify the key-value to be deleted.

Copy
<xsql-script>
    <body>
        <set name='m1'>
            <map>
                <item><string>RAQUET</string><number>10</number></item>
                <item><string>BALL</string><number>100</number></item>
            </map>
        </set>

        
        <map.remove name='m1'>
            <string>RAQUET</string>
        </map.remove>

        <println>
            <m1 />
        </println>
    </body>
</xsql-script>
{BALL=100}
 

3.4 Obtaining an Entry

In order to get the value of an entry, the corresponding key must be specified.

Copy
<xsql-script>
    <body>
        <set name='m1'>
            <map>
                <item><string>RAQUET</string><number>10</number></item>
                <item><string>BALL</string><number>100</number></item>
            </map>
        </set>

        
        <println>
            <map.get name='m1'>
                <string>RAQUET</string>
            </map.get>
        </println>
    </body>
</xsql-script>
10
 

4 Other Operations

 

4.1 Iterative Traversal

TO DO

This section is incomplete and will be concluded as soon as possible.
 

4.2 Empty

TO DO

This section is incomplete and will be concluded as soon as possible.
 

4.3 Cloning

TO DO

This section is incomplete and will be concluded as soon as possible.
 

5 Virtual Tables (vtable)

TO DO

This section is incomplete and will be concluded as soon as possible.