/opengles/src/codegen/bitset.h

http://ftk.googlecode.com/ · C Header · 82 lines · 31 code · 22 blank · 29 comment · 1 complexity · 9c9a00ad12f3d81ce5078b637df2aa19 MD5 · raw file

  1. #ifndef CODEGEN_BITSET_H
  2. #define CODEGEN_BITSET_H 1
  3. /****************************************************************************/
  4. /* */
  5. /* Copyright (c) 2004, Hans-Martin Will. All rights reserved. */
  6. /* */
  7. /* Redistribution and use in source and binary forms, with or without */
  8. /* modification, are permitted provided that the following conditions are */
  9. /* met: */
  10. /* */
  11. /* * Redistributions of source code must retain the above copyright */
  12. /* notice, this list of conditions and the following disclaimer. */
  13. /* */
  14. /* * Redistributions in binary form must reproduce the above copyright */
  15. /* notice, this list of conditions and the following disclaimer in the */
  16. /* documentation and/or other materials provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
  19. /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
  20. /* LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
  21. /* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER */
  22. /* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
  23. /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, */
  24. /* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
  25. /* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  26. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
  27. /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
  28. /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  29. /* */
  30. /****************************************************************************/
  31. #include "codegen.h"
  32. #include "heap.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #define CG_BITSET_BITS_PER_WORD 32
  37. typedef struct cg_bitset_t
  38. {
  39. size_t elements;
  40. U32 bits[1];
  41. }
  42. cg_bitset_t;
  43. cg_bitset_t * cg_bitset_create(cg_heap_t * heap, size_t elements);
  44. void cg_bitset_assign(cg_bitset_t * target, cg_bitset_t * source);
  45. /* target = target U (source \ minus) */
  46. int cg_bitset_union_minus(cg_bitset_t * target, cg_bitset_t * source,
  47. cg_bitset_t * minus);
  48. int cg_bitset_union(cg_bitset_t * target, cg_bitset_t * source);
  49. int cg_bitset_intersects(const cg_bitset_t * first, const cg_bitset_t * second);
  50. #define CG_BITSET_TEST(bitset, element) \
  51. (((bitset->bits)[(element) / CG_BITSET_BITS_PER_WORD] & \
  52. (1 << ((element) % CG_BITSET_BITS_PER_WORD))) != 0)
  53. #define CG_BITSET_SET(bitset, element) \
  54. ((bitset->bits)[(element) / CG_BITSET_BITS_PER_WORD] |= (1 << ((element) % CG_BITSET_BITS_PER_WORD)))
  55. #define CG_BITSET_CLEAR(bitset, element) \
  56. ((bitset->bits)[(element) / CG_BITSET_BITS_PER_WORD] &= ~(1 << ((element) % CG_BITSET_BITS_PER_WORD)))
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif //ndef CODEGEN_BITSET_H