Advertisement
DraKiNs

[COD] switch Strings

Oct 24th, 2011
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.00 KB | None | 0 0
  1. /*=================================================================
  2.          _ ____         _____             __  __
  3.         (_)  _ \ ___  |_   _|__  __ _|  \/  |
  4.         | | |_) / __|   | |/ _ \/ _` | |\/| |
  5.         | |  __/\__ \   | |  __/ (_| | |  | |
  6.         |_|_|   |___/   |_|\___|\__,_|_|  |_|
  7.  
  8.             Created by Bruno da Silva
  9.             www.ips-team.blogspot.com
  10.         Fasthest check string with case/switch
  11.  
  12. =================================================================*/
  13.  
  14. #define switchStr(%0)       switch(dracoHash(%0))
  15. #define string<%0>      dracoHash(#%0)     
  16.  
  17.  
  18. new s1 = 1;
  19. new s2 = 0;
  20. new length;
  21.  
  22. stock dracoHash(buf[])
  23. {  
  24.     length = strlen(buf);
  25.     s1 = 1,     s2 = 0;
  26.  
  27.     for (new n; n < length; ++n)
  28.     {
  29.         s1 = (s1 + buf[n]) % 65521;
  30.         s2 = (s2 + s1)     % 65521;
  31.     }
  32.     return (s2 << 16) + s1;
  33.  } 
  34.  
  35.  
  36. // =========== [ Example ] =========
  37.  
  38. switchStr("drakins")
  39. {
  40.     case string<drakon>:
  41.     {
  42.         print("is drakon");
  43.     }
  44.  
  45.     case string<drakins>:
  46.     {
  47.         print("is drakins");
  48.     }
  49.    
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement