[Include] ArrayList for PAWN
#1

Hello everyone!

Yesterday I was doing something in java with an ArrayList, so I got the idea to do a ArrayList for PAWN...

This is a include which allows you to create arrays with changeable size trough functions.

Also, when you remove something all upper values in array will move on that place, so size of array will be -1.


Here is a list of functions with explain.


ArrayList:NewArrayList<TYPE>(capacity);
@ <TYPE> - Is type of ArrayList, it can be FLOAT or INTEGER
@ (capacity) - Changeable capacity on array

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5); 
_______________________________________


ArrayList:: Destroy (ArrayList:ArrayListID);
@ ArrayList:ArrayListID - ID / Address of ArrayList which we want destroy

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Destroy(myList); 
_______________________________________


ArrayList::IsValid(ArrayList:ArrayListID);
@ ArrayList:ArrayListID - ID / Address of ArrayList which we want check

Example:
PHP код:
if (ArrayList::IsValid(myList))
    print (
"List exist");
else 
    print (
"List not exist"); 
_______________________________________


ArrayList::Add (ArrayList:ArrayListID, value);
@ ArrayList:ArrayListID - ID / Address of ArrayList
@ value - Value which we want add into list

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234);
new 
ArrayList:floatList NewArrayList<FLOAT>(2);
ArrayList::Add (floatList55.0564495); 
_______________________________________


ArrayList::Remove(ArrayList:ArrayListID, index);
@ ArrayList:ArrayListID - ID / Address of ArrayList
@ index - Index in list

NOTE: When you remove example index 2, all upper indexes will move to -1
NOTE: For this is better use ArrayList::IndexOf function, explain down


Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
ArrayList::Remove (myList1); //123
// this is better and safely
ArrayList::Remove (myListArrayList::IndexOf (myList123); // This will remove index where is value '123' 
_______________________________________


ArrayList::Size(ArrayList:ArrayListID);
@ ArrayList:ArrayListID - ID / Address of ArrayList

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
new 
size ArrayList::Size (myList);
print (
size); // This will print 3 
_______________________________________


ArrayList::Capacity(ArrayList:ArrayListID);
@ ArrayList:ArrayListID - ID / Address of ArrayList

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
new 
capacity ArrayList::Capacity(myList);
print (
capacity); // This will print 5 
_______________________________________


ArrayList::Get (ArrayList:ArrayListID, index);
@ ArrayList:ArrayListID - ID / Address of ArrayList
@ index - Return value from index

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
new 
index2 ArrayList::Get (myList2);
print (
index2); // This will print 687654 
_______________________________________


ArrayList::EnsureCapacity (ArrayList:ArrayListID, newcapacity);
@ ArrayList:ArrayListID - ID / Address of ArrayList
@ newcapacity - New capacity value

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5); // Capacity now is 5
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
ArrayList::EnsureCapacity (myList15); // Now capacity of myList is 15 
_______________________________________


ArrayList::Clear(ArrayList:ArrayListID);
@ ArrayList:ArrayListID - ID / Address of ArrayList

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5); // Capacity now is 5
ArrayList::Add (myList45641234);
ArrayList::Add (myList123);
ArrayList::Add (myList687654);
// This will clear all values in this list
ArrayList::Clear(myList); 
_______________________________________


ArrayList::IndexOf (ArrayList:ArrayListID, value);
@ ArrayList:ArrayListID - ID / Address of ArrayList
@ value - Value from which we want get index

Example:
PHP код:
new ArrayList:myList NewArrayList<INTEGER>(5);
ArrayList::Add (myList45641234); // index 0
ArrayList::Add (myList123); // index 1
ArrayList::Add (myList687654); //index 2 - we want this
new index ArrayList::IndexOf (myList687654); // now index variable is 2 

___________________________________________

Changes:
-
-
-




Bugs:
Wrong read values (FIXED*)
-
-



Download:
Version (1.0) available on GitHub on next link - https://github.com/Ino42O/PawnArrayList



An example script - https://github.com/Ino42O/PawnArrayL...istExample.pwn


SPEED TEST:

1000 items test:
Код:
[14:41:15] Test with 1000 items
[14:41:15] Created and inserted items in 2ms, Readed in 2ms
10000 items test:
Код:
[14:41:26] Test with 10000 items
[14:41:26] Created and inserted items in 151ms, Readed in 149ms
15000 items test:
Код:
[14:41:44] Test with 15000 items
[14:41:44] Created and inserted items in 341ms, Readed in 335ms
Reply
#2

Nice work and well done Ino !
Reply
#3

Good job man,thanks.Can you check your private message box please i have a question?
Reply
#4

Nice. Do some benchmarks
Reply
#5

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
Nice. Do some benchmarks
Quote:

Yea man.. i will probably release it tomorrow.

there is a speed with inserting and reading data from arraylist

1000 items
[22:51:23] Test with 1000 items
[22:51:23] Created and inserted items in 3ms, Readed in 128ms

15000
[22:52:57] Test with 15000 items
[22:52:57] Created and inserted items in 353ms, Readed in 1401ms

65535
[22:54:27] Test with 65535 items
[22:54:27] Created and inserted items in 6530ms, Readed in 11748ms

Awesome job!
Reply
#6

Good job
rep+
Reply
#7

Thanks guys
Reply
#8

Quote:
[22:54:27] Test with 65535 items
[22:54:27] Created and inserted items in 6530ms, Readed in 11748ms
Interesting. Can we see the code for banchmark?
Reply
#9

Код:
// 65535
// change test to number which you want

        new test = 0xFFFF;
	new t1 = GetTickCount();
	new ArrayList:l = NewArrayList<INTEGER>(test);

	for (new i = 0; i < test; i++)
		ArrayList::Add(l, i);

	new t1end = GetTickCount() - t1;

	new t2 = GetTickCount();

	for (new i = 0; i < test; i++)
		printf ("%d", ArrayList::Get(l, i));

	new t2end = GetTickCount() - t2;

	printf ("Test with %d items", test);
	printf ("Created and inserted items in %dms, Readed in %dms", t1end, t2end);
Reply
#10

Quote:
Originally Posted by Ivan_Ino
Посмотреть сообщение
Код:
// 65535
// change test to number which you want

        new test = 0xFFFF;
	new t1 = GetTickCount();
	new ArrayList:l = NewArrayList<INTEGER>(test);

	for (new i = 0; i < test; i++)
		ArrayList::Add(l, i);

	new t1end = GetTickCount() - t1;

	new t2 = GetTickCount();

	for (new i = 0; i < test; i++)
		printf ("%d", ArrayList::Get(l, i));

	new t2end = GetTickCount() - t2;

	printf ("Test with %d items", test);
	printf ("Created and inserted items in %dms, Readed in %dms", t1end, t2end);
That test is invalid... D:

The 'print' function is slow as fuck so the speed you're testing is likely just the prints.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)