Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / xbt / mmalloc / swag.h
1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /* Warning, this module is done to be efficient and performs tons of cast and dirty things. So avoid using it unless
7  * you really know what you are doing. */
8
9 #ifndef XBT_SWAG_H
10 #define XBT_SWAG_H
11
12 #include "xbt/sysdep.h" /* size_t */
13
14 /*
15  * XBT_swag: a O(1) set based on linked lists
16  *
17  *  Warning, this module is done to be efficient and performs tons of cast and dirty things. So make sure you know what
18  *  you are doing while using it.
19  *  It is basically a fifo but with restrictions so that it can be used as a set. Any operation (add, remove, belongs)
20  *  is O(1) and no call to malloc/free is done.
21  *
22  *  @deprecated If you are using C++, you might want to use `boost::intrusive::set` instead.
23  */
24
25 /* Swag types
26  *
27  *  Specific set.
28  *
29  *  These typedefs are public so that the compiler can do his job but believe me, you don't want to try to play with
30  *  those structs directly. Use them as an abstract datatype.
31  */
32
33 typedef struct xbt_swag_hookup {
34   void *next;
35   void *prev;
36 } s_xbt_swag_hookup_t;
37
38 /* This type should be added to a type that is to be used in a swag.
39  *
40  *  Whenever a new object with this struct is created, all fields have to be set to NULL
41  *
42  * Here is an example like that :
43
44 \code
45 typedef struct foo {
46   s_xbt_swag_hookup_t set1_hookup;
47   s_xbt_swag_hookup_t set2_hookup;
48
49   double value;
50 } s_foo_t, *foo_t;
51 ...
52 {
53   s_foo_t elem;
54   xbt_swag_t set1=NULL;
55   xbt_swag_t set2=NULL;
56
57   set1 = xbt_swag_new(xbt_swag_offset(elem, set1_hookup));
58   set2 = xbt_swag_new(xbt_swag_offset(elem, set2_hookup));
59
60 }
61 \endcode
62 */
63
64 struct xbt_swag {
65   void *head;
66   void *tail;
67   size_t offset;
68   int count;
69 };
70 typedef struct xbt_swag s_xbt_swag_t;
71
72 #endif /* XBT_SWAG_H */