Raised This Month: $ Target: $400
 0% 

How to get unique id from array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-27-2022 , 09:09   Re: How to get unique id from array
Reply With Quote #1

Okay, use this:
PHP Code:
getUniqueElements(inputnumElementsoutput, &numUnique)
{
    new 
Trie:set TrieCreate();
    new 
strKey[12];
    
    for(new 
0numElementsi++)
    {
        
num_to_str(input[i], strKeycharsmax(strKey));
        if(!
TrieKeyExists(setstrKey))
        {
            
output[numUnique++] = arr[i];
            
TriePushCell(setstrKey0);
        }
    }
    
    
TrieDestroy(set);

Call it like this:

PHP Code:
//assuming you have an array ids you want to process with numIds ids inside it

new uniqueIds[SIZE_HERE]
int numUnique;
getUniqueElements(idsnumIdsuniqueIdsnumUnique)

for(
int i 0numUniquei++)
{
    
//do something with uniqueIds[i]

That's all you need to know to use it. Everything else was just extra information and explanations about why I suggested both solutions.
__________________

Last edited by HamletEagle; 05-27-2022 at 09:09.
HamletEagle is offline
Mikka
Member
Join Date: Dec 2018
Old 05-27-2022 , 09:13   Re: How to get unique id from array
Reply With Quote #2

is this stock to be called inside a function with motd?

Quote:
Originally Posted by HamletEagle View Post
Okay, use this:
PHP Code:
getUniqueElements(inputnumElementsoutput, &numUnique)
{
    new 
Trie:set TrieCreate();
    new 
strKey[12];
    
    for(new 
0numElementsi++)
    {
        
num_to_str(input[i], strKeycharsmax(strKey));
        if(!
TrieKeyExists(setstrKey))
        {
            
output[numUnique++] = arr[i];
            
TriePushCell(setstrKey0);
        }
    }
    
    
TrieDestroy(set);

Mikka is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 21:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode