sqstring.h 794 B

12345678910111213141516171819202122232425262728293031
  1. /* see copyright notice in squirrel.h */
  2. #ifndef _SQSTRING_H_
  3. #define _SQSTRING_H_
  4. inline SQHash _hashstr (const SQChar *s, size_t l)
  5. {
  6. SQHash h = (SQHash)l; /* seed */
  7. size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */
  8. for (; l>=step; l-=step)
  9. h = h ^ ((h<<5)+(h>>2)+(unsigned short)*(s++));
  10. return h;
  11. }
  12. struct SQString : public SQRefCounted
  13. {
  14. SQString(){}
  15. ~SQString(){}
  16. public:
  17. static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 );
  18. SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
  19. void Release();
  20. SQSharedState *_sharedstate;
  21. SQString *_next; //chain for the string table
  22. SQInteger _len;
  23. SQHash _hash;
  24. SQChar _val[1];
  25. };
  26. #endif //_SQSTRING_H_