Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

[Include] ArrayList for PAWN

$
0
0
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:
-
-
-



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


1000 indexes in test
PHP Code:

Created and inserted 1000 items in 3msReaded 1000 items in 129ms 


Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>