-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add array_sort and fully migrate to sampctl
- Loading branch information
Showing
6 changed files
with
344 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Package only files | ||
# | ||
|
||
# Compiled Bytecode, precompiled output and assembly | ||
*.amx | ||
*.lst | ||
*.asm | ||
|
||
# Vendor directory for dependencies | ||
dependencies/ | ||
|
||
# Dependency versions lockfile | ||
pawn.lock | ||
|
||
|
||
# | ||
# Server/gamemode related files | ||
# | ||
|
||
# compiled settings file | ||
# keep `samp.json` file on version control | ||
# but make sure the `rcon_password` field is set externally | ||
# you can use the environment variable `SAMP_RCON_PASSWORD` to do this. | ||
server.cfg | ||
|
||
# Plugins directory | ||
plugins/ | ||
|
||
# binaries | ||
*.exe | ||
*.dll | ||
*.so | ||
announce | ||
samp03svr | ||
samp-npc | ||
|
||
# logs | ||
logs/ | ||
server_log.txt | ||
crashinfo.txt | ||
|
||
# Ban list | ||
samp.ban | ||
|
||
# | ||
# Common files | ||
# | ||
|
||
*.sublime-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build only", | ||
"type": "shell", | ||
"command": "sampctl package build", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"isBackground": false, | ||
"presentation": { | ||
"reveal": "silent", | ||
"panel": "dedicated" | ||
}, | ||
"problemMatcher": "$sampctl" | ||
}, | ||
{ | ||
"label": "build watcher", | ||
"type": "shell", | ||
"command": "sampctl package build --watch", | ||
"group": "build", | ||
"isBackground": true, | ||
"presentation": { | ||
"reveal": "silent", | ||
"panel": "dedicated" | ||
}, | ||
"problemMatcher": "$sampctl" | ||
}, | ||
{ | ||
"label": "run tests", | ||
"type": "shell", | ||
"command": "sampctl package run", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
}, | ||
"isBackground": true, | ||
"presentation": { | ||
"reveal": "silent", | ||
"panel": "dedicated" | ||
}, | ||
"problemMatcher": "$sampctl" | ||
}, | ||
{ | ||
"label": "run tests watcher", | ||
"type": "shell", | ||
"command": "sampctl package run --watch", | ||
"group": "test", | ||
"isBackground": true, | ||
"presentation": { | ||
"reveal": "silent", | ||
"panel": "dedicated" | ||
}, | ||
"problemMatcher": "$sampctl" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# pawn-array-util | ||
|
||
[![sampctl](https://shields.southcla.ws/badge/sampctl-pawn--array--util-2f2f2f.svg?style=for-the-badge)](https://github.com/Vince0789/pawn-array-util) | ||
|
||
<!-- | ||
Short description of your library, why it's useful, some examples, pictures or | ||
videos. Link to your forum release thread too. | ||
Remember: You can use "forumfmt" to convert this readme to forum BBCode! | ||
What the sections below should be used for: | ||
`## Installation`: Leave this section un-edited unless you have some specific | ||
additional installation procedure. | ||
`## Testing`: Whether your library is tested with a simple `main()` and `print`, | ||
unit-tested, or demonstrated via prompting the player to connect, you should | ||
include some basic information for users to try out your code in some way. | ||
And finally, maintaining your version number`: | ||
* Follow [Semantic Versioning](https://semver.org/) | ||
* When you release a new version, update `VERSION` and `git tag` it | ||
* Versioning is important for sampctl to use the version control features | ||
Happy Pawning! | ||
--> | ||
|
||
## Installation | ||
|
||
Simply install to your project: | ||
|
||
```bash | ||
sampctl package install Vince0789/pawn-array-util | ||
``` | ||
|
||
Include in your code and begin using the library: | ||
|
||
```pawn | ||
#include <array_util> | ||
``` | ||
|
||
## Usage | ||
|
||
### array_shift | ||
```pawn | ||
stock array_shift(array[], value, size = sizeof array) | ||
``` | ||
Appends `value` to the end of `array`. Pushes the first value off and returns it, moves everything down. | ||
|
||
### array_unshift | ||
```pawn | ||
stock array_unshift(array[], value, size = sizeof array) | ||
``` | ||
Inserts `value` at the start of `array`. Pushes the last value off and returns it, moves everything up. | ||
|
||
### array_sort | ||
```pawn | ||
stock array_sort(arr[], left = 0, right = sizeof arr) | ||
``` | ||
Sorts `array` in ascending order. Implementation of the QuickSort algorithm. This function does not return any value. | ||
|
||
### in_array | ||
```pawn | ||
stock bool:in_array(needle, const haystack[], &index = 0, size = sizeof haystack) | ||
``` | ||
Returns `true` if `needle` is in `haystack`, false otherwise. Using the `index` parameter, this function can be used in a while loop to find all instances of a certain value: | ||
|
||
```pawn | ||
new index = -1; | ||
while(in_array(5, theArrayToSearch, index)) | ||
{ | ||
printf("found 5 at index: %d", index); | ||
} | ||
``` | ||
|
||
## Testing | ||
|
||
<!-- | ||
Depending on whether your package is tested via in-game "demo tests" or | ||
y_testing unit-tests, you should indicate to readers what to expect below here. | ||
--> | ||
|
||
To test, simply run the package: | ||
|
||
```bash | ||
sampctl package run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"user": "Vince0789", | ||
"repo": "pawn-array-util", | ||
"contributors": ["Vince0789"] | ||
"user": "Vince0789", | ||
"repo": "pawn-array-util", | ||
"entry": "test.pwn", | ||
"output": "test.amx", | ||
"dependencies": [ | ||
"sampctl/samp-stdlib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <a_samp> | ||
#include "array_util.inc" | ||
|
||
main() | ||
{ | ||
testShift(); | ||
testUnshift(); | ||
testInArray(); | ||
testSort(); | ||
} | ||
|
||
testShift() | ||
{ | ||
printf("\narray_shift"); | ||
printf("-----------"); | ||
|
||
new arrayToShift[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; | ||
|
||
printf("before shifting:"); | ||
printArray(arrayToShift); | ||
|
||
new firstValue = array_shift(arrayToShift, 89); | ||
|
||
printf("after shifting:"); | ||
printArray(arrayToShift); | ||
printf("value that was shifted off: %d", firstValue); | ||
} | ||
|
||
testUnshift() | ||
{ | ||
printf("\narray_unshift"); | ||
printf("-------------"); | ||
|
||
new arrayToShift[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; | ||
|
||
printf("before shifting:"); | ||
printArray(arrayToShift); | ||
|
||
new lastValue = array_unshift(arrayToShift, 89); | ||
|
||
printf("after shifting:"); | ||
printArray(arrayToShift); | ||
printf("value that was shifted off: %d", lastValue); | ||
} | ||
|
||
testInArray() | ||
{ | ||
printf("\nin_array"); | ||
printf("--------"); | ||
|
||
new testArray[] = {1, 3, 5, 7, 13, 5, 1, 7, 3}; | ||
|
||
printf("array to search in:"); | ||
printArray(testArray); | ||
printf("finding all the indexes that contain the number 5:"); | ||
|
||
new index = -1; | ||
|
||
while(in_array(5, testArray, index)) | ||
{ | ||
printf("found 5 at index: %d", index); | ||
} | ||
} | ||
|
||
testSort() | ||
{ | ||
printf("\narray_sort"); | ||
printf("----------"); | ||
|
||
new arrayToSort[] = {13, 92, 85, 64, 17, 55, 33, 60, 58, 95}; | ||
|
||
printf("before sort:"); | ||
printArray(arrayToSort); | ||
|
||
array_sort(arrayToSort); | ||
|
||
printf("after sort:"); | ||
printArray(arrayToSort); | ||
} | ||
|
||
printArray(const arr[], size = sizeof arr) | ||
{ | ||
new output[128]; | ||
|
||
for(new i; i < size; i++) | ||
{ | ||
new tmp[11]; | ||
format(tmp, sizeof tmp, "%d", arr[i]); | ||
|
||
if(i > 0) | ||
{ | ||
strcat(output, ", "); | ||
} | ||
|
||
strcat(output, tmp); | ||
} | ||
|
||
print(output); | ||
} |