The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
array.h File Reference

This is the implementation of a dynamic array, used for managing various data structures. More...

#include <mm/dymelor.h>
#include <memory.h>
+ Include dependency graph for array.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INIT_SIZE_ARRAY   8U
 
#define rootsim_array(type)
 
#define array_items(self)   ((self).items)
 
#define array_count(self)   ((self).count)
 
#define array_capacity(self)   ((self).capacity)
 
#define array_shrink(self)
 
#define array_expand(self)
 
#define array_new(type)
 
#define array_free(self)
 
#define array_init(self)
 
#define array_fini(self)
 
#define array_reserve(self, count)
 
#define array_push(self, elem)
 
#define array_pop(self)
 
#define array_add_at(self, i, elem)
 
#define array_lazy_remove_at(self, i)
 
#define array_remove_at(self, i)
 
#define array_remove(self, elem)
 
#define array_peek(self)   (array_items(self)[array_count(self)-1])
 
#define array_get_at(self, i)   (array_items(self)[i])
 
#define array_empty(self)   (array_count(self) == 0)
 
#define array_dump_size(self)
 
#define array_dump(self, mem_area)
 
#define array_load(self, mem_area)
 

Detailed Description

This is the implementation of a dynamic array, used for managing various data structures.

Copyright (C) 2008-2018 HPDCS Group http://www.dis.uniroma1.it/~hpdcs

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.

ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Andrea Piccione
Date
18 June 2018

Definition in file array.h.

Macro Definition Documentation

#define array_add_at (   self,
  i,
  elem 
)
Value:
({ \
if(unlikely(array_count(self) <= (i))) \
rootsim_error(true, "out of bound add in a dynamic array"); \
array_expand(self); \
memmove(&(array_items(self)[(i)+1]), &(array_items(self)[(i)]), sizeof(*array_items(self)) * (array_count(self)-(i))); \
array_items(self)[(i)] = (elem); \
array_count(self)++; \
})
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74

Definition at line 109 of file array.h.

#define array_dump (   self,
  mem_area 
)
Value:
({ \
memcpy((mem_area), &array_count(self), sizeof(array_count(self))); \
(mem_area) = ((unsigned char *)(mem_area)) + sizeof(array_count(self)); \
memcpy((mem_area), array_items(self), array_count(self) * sizeof(*array_items(self))); \
mem_area = ((unsigned char *)(mem_area)) + array_count(self) * sizeof(*array_items(self)); \
})

Definition at line 160 of file array.h.

#define array_dump_size (   self)
Value:
({ \
sizeof(array_count(self)) + array_count(self)*sizeof(*array_items(self)); \
})

Definition at line 156 of file array.h.

#define array_expand (   self)
Value:
({ \
if(array_count(self) >= array_capacity(self)){\
array_capacity(self) *= 2; \
array_items(self) = rsrealloc(array_items(self), array_capacity(self) * sizeof(*array_items(self))); \
} \
})

Definition at line 57 of file array.h.

#define array_fini (   self)
Value:
({ \
rsfree(array_items(self)); \
})

Definition at line 82 of file array.h.

#define array_free (   self)
Value:
({ \
rsfree(array_items(self)); \
rsfree(&(self)); \
})

Definition at line 71 of file array.h.

#define array_init (   self)
Value:
({ \
array_capacity(self) = INIT_SIZE_ARRAY; \
array_items(self) = rsalloc(array_capacity(self) * sizeof(*array_items(self))); \
array_count(self) = 0; \
})

Definition at line 76 of file array.h.

#define array_lazy_remove_at (   self,
 
)
Value:
({ \
if(unlikely(array_count(self) <= (i))) \
rootsim_error(true, "out of bound removal in a dynamic array"); \
__typeof__(*array_items(self)) __rmval; \
array_count(self)--; \
__rmval = array_items(self)[(i)]; \
array_items(self)[(i)] = array_items(self)[array_count(self)]; \
array_shrink(self); \
__rmval; \
})
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74

Definition at line 118 of file array.h.

#define array_load (   self,
  mem_area 
)
Value:
({ \
memcpy(&array_count(self), (mem_area), sizeof(array_count(self))); \
(mem_area) = ((unsigned char *)(mem_area)) + sizeof(array_count(self)); \
array_capacity(self) = max(array_count(self), INIT_SIZE_ARRAY); \
array_items(self) = rsalloc(array_capacity(self) * sizeof(*array_items(self))); \
memcpy(array_items(self), (mem_area), array_count(self) * sizeof(*array_items(self))); \
(mem_area) = ((unsigned char *)(mem_area)) + (array_count(self) * sizeof(*array_items(self))); \
})
#define max(a, b)
Macro to find the maximum among two values.
Definition: core.h:106

Definition at line 167 of file array.h.

#define array_new (   type)
Value:
({ \
rootsim_array(type) *__newarr; \
__newarr = rsalloc(sizeof(*__newarr)); \
array_init(*__newarr);\
__newarr; \
})

Definition at line 64 of file array.h.

#define array_pop (   self)
Value:
({ \
if(unlikely(!array_count(self))) \
rootsim_error(true, "pop of an empty array"); \
__typeof__(*array_items(self)) __popval; \
array_count(self)--; \
__popval = array_items(self)[array_count(self)]; \
array_shrink(self); \
__popval; \
})
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74

Definition at line 99 of file array.h.

#define array_push (   self,
  elem 
)
Value:
({ \
array_expand(self); \
array_items(self)[array_count(self)] = (elem); \
array_count(self)++; \
})

Definition at line 93 of file array.h.

#define array_remove (   self,
  elem 
)
Value:
({ \
typeof(array_count(self)) __cntr = array_count(self); \
while(__cntr--){ \
if(array_items(self)[__cntr] == (elem)){\
array_remove_at(self, __cntr); \
break; \
} \
} \
})

Definition at line 140 of file array.h.

#define array_remove_at (   self,
 
)
Value:
({ \
if(unlikely(array_count(self) <= (i))) \
rootsim_error(true, "out of bound removal in a dynamic array"); \
__typeof__(*array_items(self)) __rmval; \
array_count(self)--; \
__rmval = array_items(self)[(i)]; \
memmove(&(array_items(self)[(i)]), &(array_items(self)[(i)+1]), sizeof(*array_items(self)) * (array_count(self)-(i))); \
array_shrink(self); \
__rmval; \
})
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74

Definition at line 129 of file array.h.

#define array_reserve (   self,
  count 
)
Value:
({ \
__typeof__(array_count(self)) __rsvidx = array_count(self); \
array_count(self) += (count); \
array_expand(self); \
&(array_items(self)[__rsvidx]); \
})

Definition at line 86 of file array.h.

#define array_shrink (   self)
Value:
({ \
if (array_count(self) > INIT_SIZE_ARRAY && array_count(self) * 3 <= array_capacity(self)) { \
array_capacity(self) /= 2; \
array_items(self) = rsrealloc(array_items(self), array_capacity(self) * sizeof(*array_items(self))); \
} \
})

Definition at line 50 of file array.h.

#define rootsim_array (   type)
Value:
struct { \
type *items; \
unsigned count, capacity; \
}

Definition at line 37 of file array.h.