Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.7 KiB

  1. /* Set object interface */
  2. #ifndef Py_SETOBJECT_H
  3. #define Py_SETOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /*
  8. There are three kinds of slots in the table:
  9. 1. Unused: key == NULL
  10. 2. Active: key != NULL and key != dummy
  11. 3. Dummy: key == dummy
  12. Note: .pop() abuses the hash field of an Unused or Dummy slot to
  13. hold a search finger. The hash field of Unused or Dummy slots has
  14. no meaning otherwise.
  15. */
  16. #define PySet_MINSIZE 8
  17. typedef struct {
  18. long hash; /* cached hash code for the entry key */
  19. PyObject *key;
  20. } setentry;
  21. /*
  22. This data structure is shared by set and frozenset objects.
  23. */
  24. typedef struct _setobject PySetObject;
  25. struct _setobject {
  26. PyObject_HEAD
  27. Py_ssize_t fill; /* # Active + # Dummy */
  28. Py_ssize_t used; /* # Active */
  29. /* The table contains mask + 1 slots, and that's a power of 2.
  30. * We store the mask instead of the size because the mask is more
  31. * frequently needed.
  32. */
  33. Py_ssize_t mask;
  34. /* table points to smalltable for small tables, else to
  35. * additional malloc'ed memory. table is never NULL! This rule
  36. * saves repeated runtime null-tests.
  37. */
  38. setentry *table;
  39. setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);
  40. setentry smalltable[PySet_MINSIZE];
  41. long hash; /* only used by frozenset objects */
  42. PyObject *weakreflist; /* List of weak references */
  43. };
  44. PyAPI_DATA(PyTypeObject) PySet_Type;
  45. PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
  46. /* Invariants for frozensets:
  47. * data is immutable.
  48. * hash is the hash of the frozenset or -1 if not computed yet.
  49. * Invariants for sets:
  50. * hash is -1
  51. */
  52. #define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type)
  53. #define PyAnySet_CheckExact(ob) \
  54. ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type)
  55. #define PyAnySet_Check(ob) \
  56. ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type || \
  57. PyType_IsSubtype((ob)->ob_type, &PySet_Type) || \
  58. PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type))
  59. PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
  60. PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
  61. PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);
  62. #define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)
  63. PyAPI_FUNC(int) PySet_Clear(PyObject *set);
  64. PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
  65. PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
  66. PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);
  67. PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);
  68. PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);
  69. PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
  70. PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* !Py_SETOBJECT_H */