SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 03/06/2016, 12:23 PM   #1
Ivan_Ino
Big Clucker
 
Join Date: Oct 2012
Location: Croatia
Posts: 102
Reputation: 120
Lightbulb ArrayList for PAWN

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 Code:
new ArrayList:myList NewArrayList<INTEGER>(5); 

_______________________________________


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

Example:
PHP Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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:
Code:
[14:41:15] Test with 1000 items
[14:41:15] Created and inserted items in 2ms, Readed in 2ms
10000 items test:
Code:
[14:41:26] Test with 10000 items
[14:41:26] Created and inserted items in 151ms, Readed in 149ms
15000 items test:
Code:
[14:41:44] Test with 15000 items
[14:41:44] Created and inserted items in 341ms, Readed in 335ms

Last edited by Ivan_Ino; 12/07/2016 at 06:22 PM.
Ivan_Ino is offline   Reply With Quote
Old 03/06/2016, 12:47 PM   #2
JustMe.77
Huge Clucker
 
JustMe.77's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 216
Reputation: 65
Default Re: ArrayList for PAWN

Nice work and well done Ino !
JustMe.77 is offline   Reply With Quote
Old 03/06/2016, 01:26 PM   #3
bybaran
Little Clucker
 
bybaran's Avatar
 
Join Date: Jun 2012
Location: Turkey
Posts: 22
Reputation: 2
Default Re: ArrayList for PAWN

Good job man,thanks.Can you check your private message box please i have a question?
bybaran is offline   Reply With Quote
Old 03/06/2016, 08:47 PM   #4
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 610
Reputation: 15
Default Re: ArrayList for PAWN

Nice. Do some benchmarks
vannesenn is offline   Reply With Quote
Old 04/06/2016, 02:20 AM   #5
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,367
Reputation: 652
Default Re: ArrayList for PAWN

Quote:
Originally Posted by vannesenn View Post
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!
Crayder is offline   Reply With Quote
Old 04/06/2016, 07:51 AM   #6
Pelle00
Little Clucker
 
Join Date: Mar 2015
Location: Republic of Srpska - Banja Luka
Posts: 6
Reputation: 0
Default Re: ArrayList for PAWN

Good job
rep+
Pelle00 is offline   Reply With Quote
Old 04/06/2016, 11:55 AM   #7
Ivan_Ino
Big Clucker
 
Join Date: Oct 2012
Location: Croatia
Posts: 102
Reputation: 120
Default Re: ArrayList for PAWN

Thanks guys
Ivan_Ino is offline   Reply With Quote
Old 04/06/2016, 12:42 PM   #8
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 610
Reputation: 15
Default Re: ArrayList for PAWN

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?
vannesenn is offline   Reply With Quote
Old 04/06/2016, 02:06 PM   #9
Ivan_Ino
Big Clucker
 
Join Date: Oct 2012
Location: Croatia
Posts: 102
Reputation: 120
Default Re: ArrayList for PAWN

Code:
// 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);
Ivan_Ino is offline   Reply With Quote
Old 04/06/2016, 05:41 PM   #10
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,367
Reputation: 652
Default Re: ArrayList for PAWN

Quote:
Originally Posted by Ivan_Ino View Post
Code:
// 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.
Crayder is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] Vectoral Pawn - STL Data containers for pawn Rancho Plugin Development 69 25/03/2019 11:50 PM
[Tool/Web/Other] PAWN Scanner - Scan PAWN files for information. Slice Tools and Files 10 15/07/2012 07:09 PM
New to pawn, trying to convert some C code to pawn CHC Scripting Help 2 22/06/2012 05:09 AM
[Help With Pawn] Pawn and compiler is not working..... D_Less Client Support 3 09/03/2012 04:49 AM


All times are GMT. The time now is 09:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.