Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20.  
  21. #include <cctype>
  22. #include <cstdint>
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "hash.h"
  27.  
  28. namespace dcx {
  29.  
  30. bool hashtable::compare_t::operator()(const char *l, const char *r) const
  31. {
  32.         for (;; ++l, ++r)
  33.         {
  34.                 uint_fast32_t ll = tolower(static_cast<unsigned>(*l)), lr = tolower(static_cast<unsigned>(*r));
  35.                 if (ll < lr)
  36.                         return true;
  37.                 if (lr < ll || !ll)
  38.                         return false;
  39.         }
  40. }
  41.  
  42. int hashtable_search(hashtable *ht, const char *key)
  43. {
  44.         auto i = ht->m.find(key);
  45.         if (i != ht->m.end())
  46.                 return i->second;
  47.         return -1;
  48. }
  49.  
  50. void hashtable_insert(hashtable *ht, const char *key, int value)
  51. {
  52.         ht->m.insert(std::make_pair(key, value));
  53. }
  54.  
  55. }
  56.