A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bugfix: I inverted the semantic of xbt_dict_get_or_null_ext and xbt_dict_get_ext...
[simgrid.git]
/
src
/
xbt
/
swag.c
diff --git
a/src/xbt/swag.c
b/src/xbt/swag.c
index 17b2c8959240167cf36647e277e898d92f56be0b..eda86e4f047cc7478d8aa5a59ada7bd1d19c7299 100644
(file)
--- a/
src/xbt/swag.c
+++ b/
src/xbt/swag.c
@@
-23,23
+23,20
@@
* \param offset where the hookup is located in the structure
* \see xbt_swag_offset
*
* \param offset where the hookup is located in the structure
* \see xbt_swag_offset
*
- * Usage : xbt_swag_new(&obj.setA-&obj);
+ * Usage : xbt_swag_new(&obj.setA-&obj);
*/
xbt_swag_t xbt_swag_new(size_t offset)
{
xbt_swag_t swag = xbt_new0(s_xbt_swag_t, 1);
*/
xbt_swag_t xbt_swag_new(size_t offset)
{
xbt_swag_t swag = xbt_new0(s_xbt_swag_t, 1);
- swag->tail = NULL;
- swag->head = NULL;
- swag->offset = offset;
- swag->count = 0;
+ xbt_swag_init(swag, offset);
return swag;
}
return swag;
}
-/**
+/**
* \param swag poor victim
* \param swag poor victim
- *
+ *
* kilkil a swag but not it's content. If you do not understand why
* xbt_swag_free should not free its content, don't use swags.
*/
* kilkil a swag but not it's content. If you do not understand why
* xbt_swag_free should not free its content, don't use swags.
*/
@@
-53,7
+50,7
@@
void xbt_swag_free(xbt_swag_t swag)
* \param offset where the hookup is located in the structure
* \see xbt_swag_offset
*
* \param offset where the hookup is located in the structure
* \see xbt_swag_offset
*
- * Usage : xbt_swag_init(swag,&obj.setA-&obj);
+ * Usage : xbt_swag_init(swag,&obj.setA-&obj);
*/
void xbt_swag_init(xbt_swag_t swag, size_t offset)
{
*/
void xbt_swag_init(xbt_swag_t swag, size_t offset)
{
@@
-64,7
+61,7
@@
void xbt_swag_init(xbt_swag_t swag, size_t offset)
}
}
-/**
+/**
* \param obj the objet to insert in the swag
* \param swag a swag
*
* \param obj the objet to insert in the swag
* \param swag a swag
*
@@
-90,7
+87,7
@@
void xbt_swag_insert(void *obj, xbt_swag_t swag)
swag->tail = obj;
}
swag->tail = obj;
}
-/**
+/**
* \param obj the objet to insert in the swag
* \param swag a swag
*
* \param obj the objet to insert in the swag
* \param swag a swag
*
@@
-117,7
+114,7
@@
void xbt_swag_insert_at_head(void *obj, xbt_swag_t swag)
swag->head = obj;
}
swag->head = obj;
}
-/**
+/**
* \param obj the objet to insert in the swag
* \param swag a swag
*
* \param obj the objet to insert in the swag
* \param swag a swag
*
@@
-144,7
+141,7
@@
void xbt_swag_insert_at_tail(void *obj, xbt_swag_t swag)
swag->tail = obj;
}
swag->tail = obj;
}
-/**
+/**
* \param obj the objet to remove from the swag
* \param swag a swag
* \return \a obj if it was in the \a swag and NULL otherwise
* \param obj the objet to remove from the swag
* \param swag a swag
* \return \a obj if it was in the \a swag and NULL otherwise
@@
-159,7
+156,7
@@
void *xbt_swag_remove(void *obj, xbt_swag_t swag)
return NULL;
if(!xbt_swag_belongs(obj, swag)) /* Trying to remove an object that
was not in this swag */
return NULL;
if(!xbt_swag_belongs(obj, swag)) /* Trying to remove an object that
was not in this swag */
-
return NULL;
+ return NULL;
if (swag->head == swag->tail) { /* special case */
if (swag->head != obj) /* Trying to remove an object that was not in this swag */
if (swag->head == swag->tail) { /* special case */
if (swag->head != obj) /* Trying to remove an object that was not in this swag */
@@
-184,7
+181,7
@@
void *xbt_swag_remove(void *obj, xbt_swag_t swag)
return obj;
}
return obj;
}
-/**
+/**
* \param swag a swag
* \return an object from the \a swag
*/
* \param swag a swag
* \return an object from the \a swag
*/
@@
-210,7
+207,7
@@
void *xbt_swag_extract(xbt_swag_t swag)
return obj;
}
return obj;
}
-/**
+/**
* \param swag a swag
* \return the number of objects in \a swag
*/
* \param swag a swag
* \return the number of objects in \a swag
*/
@@
-219,7
+216,7
@@
int xbt_swag_size(xbt_swag_t swag)
return (swag->count);
}
return (swag->count);
}
-/**
+/**
* \param obj an object
* \param swag a swag
* \return 1 if \a obj is in the \a swag and 0 otherwise
* \param obj an object
* \param swag a swag
* \return 1 if \a obj is in the \a swag and 0 otherwise
@@
-227,7
+224,7
@@
int xbt_swag_size(xbt_swag_t swag)
int xbt_swag_belongs(void *obj, xbt_swag_t swag)
{
return ((NEXT(obj, swag->offset)) || (PREV(obj, swag->offset))
int xbt_swag_belongs(void *obj, xbt_swag_t swag)
{
return ((NEXT(obj, swag->offset)) || (PREV(obj, swag->offset))
-
|| (swag->head == obj));
+ || (swag->head == obj));
}
}
@@
-246,15
+243,15
@@
XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") {
shmurtz_t obj1, obj2, obj;
xbt_swag_t setA,setB;
shmurtz_t obj1, obj2, obj;
xbt_swag_t setA,setB;
- obj1 =
calloc(1,sizeof(s_shmurtz_t)
);
- obj2 =
calloc(1,sizeof(s_shmurtz_t)
);
+ obj1 =
xbt_new0(s_shmurtz_t,1
);
+ obj2 =
xbt_new0(s_shmurtz_t,1
);
obj1->name="Obj 1";
obj2->name="Obj 2";
xbt_test_add0("Basic usage");
xbt_test_log3("%p %p %ld\n",obj1,&(obj1->setB),
obj1->name="Obj 1";
obj2->name="Obj 2";
xbt_test_add0("Basic usage");
xbt_test_log3("%p %p %ld\n",obj1,&(obj1->setB),
- (long)((char *)&(obj1->setB) - (char *)obj1));
+
(long)((char *)&(obj1->setB) - (char *)obj1));
setA = xbt_swag_new(xbt_swag_offset(*obj1,setA));
setB = xbt_swag_new(xbt_swag_offset(*obj1,setB));
setA = xbt_swag_new(xbt_swag_offset(*obj1,setA));
setB = xbt_swag_new(xbt_swag_offset(*obj1,setB));
@@
-286,6
+283,9
@@
XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") {
xbt_test_assert(xbt_swag_size(setA) == 2);
xbt_test_assert(xbt_swag_size(setB) == 1);
xbt_test_assert(xbt_swag_size(setA) == 2);
xbt_test_assert(xbt_swag_size(setB) == 1);
+
+ xbt_swag_free(setA);
+ xbt_swag_free(setB);
}
#endif /* SIMGRID_TEST */
}
#endif /* SIMGRID_TEST */