|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



LIST



There are two of lists in e language
-- Regular list
-- Keyed list Regular



Regular List



-List types hold ordered collections of data elements.
-All items in a list must be of the same type.
-List elements can be of any type.
-Items in a list can be indexed with the subscript operator [ ], by placing a non-negative integer expression in the brackets.
-List indexes start at zero. You can select an item from a list by specifying its index.
-Lists are dynamically resizable.
-Lists contain many predefined methods.
-Lists are defined by using the list of keyword in a variable or a field definition.



EXAMPLE:
lis : list of int;


List Operations



size() : This is used to set the size of the list.
add(item or list) : Add an item to the end of a list
add0(item or list) : Add an item to the head of a list
clear(): Delete all items from a list
delete(index) : Delete an item from a list
insert(index,item) : Insert an item in a list at a specified index
pop(item) : Remove and return the last list item
pop0(item) : Remove and return the first list item
push(item) : Add an item to the end of a list
push0(item) : Add an item to the head of a list
resize() : Change the size of a list




EXAMPLE:
<'
extend sys {
run() is also {
var a_list: list of int = {1;2;3;4};
var b_list: list of int = {5;5};
print a_list;
print a_list.pop();
a_list.add(9);
print a_list;
a_list.insert(2,33);
print a_list;
a_list.add(b_list);
print a_list;
a_list.delete(4);
print a_list;
a_list.add0(22);
print a_list;
print a_list.pop0();
a_list.push(44);
print a_list;
a_list.push0(55);
print a_list;
a_list.resize(4);
print a_list;
a_list.clear();
print a_list;
}
};
'>
RESULT:

a_list =
0. 1
1. 2
2. 3
3. 4
a_list.pop() = 4
a_list =
0. 1
1. 2
2. 3
3. 9
a_list =
0. 1
1. 2
2. 33
3. 3
4. 9
a_list =
0. 1
1. 2
2. 33
3. 3
4. 9
5. 5
6. 5
a_list =
0. 1
1. 2
2. 33
3. 3
4. 5
5. 5
a_list =
0. 22
1. 1
2. 2
3. 33
4. 3
5. 5
6. 5
a_list.pop0() = 22
a_list =
0. 1
1. 2
2. 33
3. 3
4. 5
5. 5
6. 44
a_list =
0. 55
1. 1
2. 2
3. 33
4. 3
5. 5
6. 5
7. 44
a_list =
0. 0
1. 0
2. 0
3. 0
a_list = (empty)


Keyed List:



A keyed list data type is similar to hash tables or association lists found in other programming languages. If the element type of the list is a scalar type or a string type, then the hash key must be the predefined implicit variable it.

A keyed list is a distinct type, different from a regular list. This means that you cannot assign a keyed list to a regular list, nor assign a regular list to a keyed list: if list_a is a keyed list and list_b is a regular list, list_a = list_b is a syntax error.



EXAMPLE:
<'
extend sys {
!a: list(key: it) of int(bits: 3);
run() is also {
var b: int(bits: 4);
for i from 0 to 10 {
gen b;
a.add(b);
};
if a.key_exists(2) then {
print a;
print a.key_index(4);
};
};
};
'>


RESULT:

a = (11 items, dec):
-3 -3 -2 1 -2 2 -1 0 -4 0 -3 .0
a.key_index(4) = 2



Index
Introduction
E Basics
Data Types
Operators
Struct
Units
List
Methods
Concurrency Actions
Constraints
Extend
When And Like
Events
Temporal Expressions
Temporal Operators 1
Temporal Operators 2
Synchronizing With The Simulator
Wait And Sync
Physical Virual Feilds
Packing N Unpacking
Pre Run N On The Fly
Coverage
Commands
Extendable Methods
Non Extendable Methods
And Gate Evc

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer