Raised This Month: $51 Target: $400
 12% 

How to make SortADTArray() case insensitive?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
step
Senior Member
Join Date: May 2010
Old 07-30-2010 , 10:50   How to make SortADTArray() case insensitive?
Reply With Quote #1

How can I do this? Do I have to write a new sorting function from scratch?
Thanks
step is offline
step
Senior Member
Join Date: May 2010
Old 07-31-2010 , 09:59   Re: How to make SortADTArray() case insensitive?
Reply With Quote #2

not possible?
step is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-31-2010 , 10:05   Re: How to make SortADTArray() case insensitive?
Reply With Quote #3

Depending on how much alike your data can be, it could be fairly easy to write a case insensitive workaround, but just as likely be a brainsqueezer.

If your data will never be exactly the same (case insensitive included), you could write it all in a buffer array all lowercased/uppercased and then sort, followed by a StrEquals case insensitive to fill your original array as it should be when sorted. (Replace the strings in the buffer with the ones they need to be with proper casing)

But that completely depends on there being no similar words with different casing. And it also depends on there not being an easier way of doing this ^^
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
step
Senior Member
Join Date: May 2010
Old 07-31-2010 , 11:34   Re: How to make SortADTArray() case insensitive?
Reply With Quote #4

Good idea! I thought of using that method, but didn't remember about StrEquals.
Thanks :D
step is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 07-31-2010 , 15:14   Re: How to make SortADTArray() case insensitive?
Reply With Quote #5

Or just use strcmp.

PHP Code:
SortADTArrayCustom(array,SortMyArray);

//...

public SortMyArray(index1,index2,Handle:array,Handle:hndl) {
    
decl String:str1[32], String:str2[32];    //replace 32 with array blocksize * 4; one cell can contain 4 characters

    
GetArrayString(array,index1,str1,sizeof(str1));
    
GetArrayString(array,index2,str2,sizeof(str2));

    return 
strcmp(str1,str2,false);

__________________
plop
p3tsin is offline
step
Senior Member
Join Date: May 2010
Old 07-31-2010 , 23:01   Re: How to make SortADTArray() case insensitive?
Reply With Quote #6

Quote:
Originally Posted by p3tsin View Post
Or just use strcmp.

PHP Code:
SortADTArrayCustom(array,SortMyArray);

//...

public SortMyArray(index1,index2,Handle:array,Handle:hndl) {
    
decl String:str1[32], String:str2[32];    //replace 32 with array blocksize * 4; one cell can contain 4 characters

    
GetArrayString(array,index1,str1,sizeof(str1));
    
GetArrayString(array,index2,str2,sizeof(str2));

    return 
strcmp(str1,str2,false);

Thanks a lot, this is exactly what I wanted :)
step is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-03-2013 , 03:22   Re: How to make SortADTArray() case insensitive?
Reply With Quote #7

so each cell are 32 bits? I'm just asking cause I though when you declare an atd array to put some string in it it should have the same block size as the max str size you were going to use. So if I want to store "hello world" in an atd array, 3 block size should be enough?

EDIT: does it include or exclude the \0?

EDIT2: sorry to revive a old thread but not allot of discution about ADT array have been made

Last edited by Mathias.; 12-03-2013 at 03:29.
Mathias. is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 12-03-2013 , 03:37   Re: How to make SortADTArray() case insensitive?
Reply With Quote #8

The sm array natives are somewhat similar to the c malloc/free, with size being 1 for each cell.
1 char per, delim counts, so you need to allocate it.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-03-2013 , 16:07   Re: How to make SortADTArray() case insensitive?
Reply With Quote #9

so the code above is wrong about the block size? He's telling us 1 cell can contain 4 char (4 byte or 32 bits)
Mathias. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-03-2013 , 16:16   Re: How to make SortADTArray() case insensitive?
Reply With Quote #10

Quote:
Originally Posted by Black-Rabbit View Post
so each cell are 32 bits? I'm just asking cause I though when you declare an atd array to put some string in it it should have the same block size as the max str size you were going to use. So if I want to store "hello world" in an atd array, 3 block size should be enough?

EDIT: does it include or exclude the \0?

EDIT2: sorry to revive a old thread but not allot of discution about ADT array have been made
When you declare an ADT array and are putting Strings in it, use ByteCountToCells to get the correct blocksize for a String of that many characters. And like String declarations, this size should include the nul terminator.

But yes, cells are 32-bits while SourceMod strings are 8-bits per character... so it's 4 characters to a cell.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-03-2013 at 16:20.
Powerlord 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 11:11.


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