Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
32ea6ea0
Commit
32ea6ea0
authored
Feb 13, 2010
by
Christoph Mallon
Browse files
Put opening curly brace of functions on a separate line.
[r27145]
parent
6b124543
Changes
179
Hide whitespace changes
Inline
Side-by-side
ir/adt/array.c
View file @
32ea6ea0
...
...
@@ -76,7 +76,8 @@ void ir_verify_arr(const void *arr)
*
* @remark Helper function, use NEW_ARR_D() instead.
*/
void
*
ir_new_arr_d
(
struct
obstack
*
obstack
,
int
nelts
,
size_t
elts_size
)
{
void
*
ir_new_arr_d
(
struct
obstack
*
obstack
,
int
nelts
,
size_t
elts_size
)
{
ir_arr_descr
*
dp
;
assert
(
obstack
&&
(
nelts
>=
0
));
...
...
@@ -99,7 +100,8 @@ void *ir_new_arr_d(struct obstack *obstack, int nelts, size_t elts_size) {
*
* @remark Helper function, use NEW_ARR_F() instead.
*/
void
*
ir_new_arr_f
(
int
nelts
,
size_t
elts_size
)
{
void
*
ir_new_arr_f
(
int
nelts
,
size_t
elts_size
)
{
ir_arr_descr
*
new
;
assert
(
nelts
>=
0
);
...
...
@@ -116,7 +118,8 @@ void *ir_new_arr_f(int nelts, size_t elts_size) {
*
* @remark Helper function, use DEL_ARR_F() instead.
*/
void
ir_del_arr_f
(
void
*
elts
)
{
void
ir_del_arr_f
(
void
*
elts
)
{
ir_arr_descr
*
dp
=
ARR_DESCR
(
elts
);
ARR_VRFY
(
elts
);
...
...
@@ -143,7 +146,8 @@ void ir_del_arr_f(void *elts) {
*
* @remark Helper function, use ARR_SETLEN() instead.
*/
void
*
ir_arr_setlen
(
void
*
elts
,
int
nelts
,
size_t
elts_size
)
{
void
*
ir_arr_setlen
(
void
*
elts
,
int
nelts
,
size_t
elts_size
)
{
ir_arr_descr
*
dp
=
ARR_DESCR
(
elts
);
assert
((
dp
->
magic
==
ARR_F_MAGIC
)
&&
(
nelts
>=
0
));
...
...
@@ -169,7 +173,8 @@ void *ir_arr_setlen (void *elts, int nelts, size_t elts_size) {
*
* @remark Helper function, use ARR_RESIZE() instead.
*/
void
*
ir_arr_resize
(
void
*
elts
,
int
nelts
,
size_t
eltsize
)
{
void
*
ir_arr_resize
(
void
*
elts
,
int
nelts
,
size_t
eltsize
)
{
ir_arr_descr
*
dp
=
ARR_DESCR
(
elts
);
int
n
;
...
...
@@ -202,7 +207,8 @@ void *ir_arr_resize(void *elts, int nelts, size_t eltsize) {
* Do NOT use is in code, use ARR_LEN() macro!
* This function is intended to be called from a debugger.
*/
int
array_len
(
const
void
*
arr
)
{
int
array_len
(
const
void
*
arr
)
{
return
ARR_LEN
(
arr
);
}
...
...
@@ -211,7 +217,8 @@ int array_len(const void *arr) {
* Do NOT use is in code!.
* This function is intended to be called from a debugger.
*/
ir_arr_descr
*
array_descr
(
const
void
*
arr
)
{
ir_arr_descr
*
array_descr
(
const
void
*
arr
)
{
if
(
!
arr
)
return
NULL
;
return
ARR_DESCR
(
arr
);
...
...
ir/adt/bipartite.c
View file @
32ea6ea0
...
...
@@ -164,7 +164,8 @@ void bipartite_dump_f(FILE *f, const bipartite_t *gr)
}
}
void
bipartite_dump
(
const
char
*
name
,
const
bipartite_t
*
gr
)
{
void
bipartite_dump
(
const
char
*
name
,
const
bipartite_t
*
gr
)
{
FILE
*
f
=
fopen
(
name
,
"w"
);
if
(
f
)
{
...
...
ir/adt/eset.c
View file @
32ea6ea0
...
...
@@ -37,7 +37,8 @@ struct eset {
#define INITIAL_SLOTS 64
static
int
pcmp
(
const
void
*
p1
,
const
void
*
p2
,
size_t
size
)
{
static
int
pcmp
(
const
void
*
p1
,
const
void
*
p2
,
size_t
size
)
{
const
void
**
q1
=
(
const
void
**
)
p1
;
const
void
**
q2
=
(
const
void
**
)
p2
;
(
void
)
size
;
...
...
@@ -46,12 +47,14 @@ static int pcmp(const void *p1, const void *p2, size_t size) {
}
eset
*
eset_create
(
void
)
{
eset
*
eset_create
(
void
)
{
return
(
eset
*
)
new_set
(
pcmp
,
INITIAL_SLOTS
);
}
eset
*
eset_copy
(
eset
*
source
)
{
eset
*
eset_copy
(
eset
*
source
)
{
eset
*
ret
=
eset_create
();
void
*
p
;
for
(
p
=
eset_first
(
source
);
p
;
p
=
eset_next
(
source
))
{
...
...
@@ -61,40 +64,47 @@ eset * eset_copy(eset *source) {
}
void
eset_destroy
(
eset
*
s
)
{
void
eset_destroy
(
eset
*
s
)
{
del_set
((
set
*
)
s
);
}
/* Returns the number of elements in the set. */
int
eset_count
(
eset
*
s
)
{
int
eset_count
(
eset
*
s
)
{
return
set_count
((
set
*
)
s
);
}
void
eset_insert
(
eset
*
s
,
void
*
p
)
{
void
eset_insert
(
eset
*
s
,
void
*
p
)
{
if
(
!
eset_contains
(
s
,
p
))
{
set_insert
((
set
*
)
s
,
&
p
,
sizeof
(
p
),
HASH_PTR
(
p
));
}
}
int
eset_contains
(
eset
*
s
,
void
*
p
)
{
int
eset_contains
(
eset
*
s
,
void
*
p
)
{
return
set_find
((
set
*
)
s
,
&
p
,
sizeof
(
p
),
HASH_PTR
(
p
))
!=
NULL
;
}
void
*
eset_first
(
eset
*
s
)
{
void
*
eset_first
(
eset
*
s
)
{
void
*
p
=
set_first
((
set
*
)
s
);
return
p
==
NULL
?
NULL
:
*
((
void
**
)
p
);
}
void
*
eset_next
(
eset
*
s
)
{
void
*
eset_next
(
eset
*
s
)
{
void
*
p
=
set_next
((
set
*
)
s
);
return
p
==
NULL
?
NULL
:
*
((
void
**
)
p
);
}
void
eset_insert_all
(
eset
*
target
,
eset
*
source
)
{
void
eset_insert_all
(
eset
*
target
,
eset
*
source
)
{
void
*
p
;
for
(
p
=
eset_first
(
source
);
p
;
p
=
eset_next
(
source
))
{
eset_insert
(
target
,
p
);
...
...
ir/adt/gaussseidel.c
View file @
32ea6ea0
...
...
@@ -41,13 +41,15 @@ struct _gs_matrix_t {
row_col_t
*
rows
;
};
static
inline
void
alloc_cols
(
row_col_t
*
row
,
int
c_cols
)
{
static
inline
void
alloc_cols
(
row_col_t
*
row
,
int
c_cols
)
{
assert
(
c_cols
>
row
->
c_cols
);
row
->
c_cols
=
c_cols
;
row
->
cols
=
XREALLOC
(
row
->
cols
,
col_val_t
,
c_cols
);
}
static
inline
void
alloc_rows
(
gs_matrix_t
*
m
,
int
c_rows
,
int
c_cols
,
int
begin_init
)
{
static
inline
void
alloc_rows
(
gs_matrix_t
*
m
,
int
c_rows
,
int
c_cols
,
int
begin_init
)
{
int
i
;
assert
(
c_rows
>
m
->
c_rows
);
...
...
@@ -64,7 +66,8 @@ static inline void alloc_rows(gs_matrix_t *m, int c_rows, int c_cols, int begin_
}
}
gs_matrix_t
*
gs_new_matrix
(
int
n_init_rows
,
int
n_init_cols
)
{
gs_matrix_t
*
gs_new_matrix
(
int
n_init_rows
,
int
n_init_cols
)
{
gs_matrix_t
*
res
=
XMALLOCZ
(
gs_matrix_t
);
if
(
n_init_rows
<
16
)
n_init_rows
=
16
;
...
...
@@ -73,7 +76,8 @@ gs_matrix_t *gs_new_matrix(int n_init_rows, int n_init_cols) {
return
res
;
}
void
gs_delete_matrix
(
gs_matrix_t
*
m
)
{
void
gs_delete_matrix
(
gs_matrix_t
*
m
)
{
int
i
;
for
(
i
=
0
;
i
<
m
->
c_rows
;
++
i
)
{
if
(
m
->
rows
[
i
].
c_cols
)
...
...
@@ -84,7 +88,8 @@ void gs_delete_matrix(gs_matrix_t *m) {
xfree
(
m
);
}
unsigned
gs_matrix_get_n_entries
(
const
gs_matrix_t
*
m
)
{
unsigned
gs_matrix_get_n_entries
(
const
gs_matrix_t
*
m
)
{
int
i
;
unsigned
n_entries
=
0
;
...
...
@@ -96,7 +101,8 @@ unsigned gs_matrix_get_n_entries(const gs_matrix_t *m) {
return
n_entries
-
m
->
n_zero_entries
;
}
int
gs_matrix_get_sizeof_allocated_memory
(
const
gs_matrix_t
*
m
)
{
int
gs_matrix_get_sizeof_allocated_memory
(
const
gs_matrix_t
*
m
)
{
int
i
,
n_col_val_ts
=
0
;
for
(
i
=
0
;
i
<
m
->
c_rows
;
++
i
)
n_col_val_ts
+=
m
->
rows
[
i
].
c_cols
;
...
...
@@ -104,13 +110,15 @@ int gs_matrix_get_sizeof_allocated_memory(const gs_matrix_t *m) {
return
n_col_val_ts
*
sizeof
(
col_val_t
)
+
m
->
c_rows
*
sizeof
(
row_col_t
)
+
sizeof
(
gs_matrix_t
);
}
void
gs_matrix_assure_row_capacity
(
gs_matrix_t
*
m
,
int
row
,
int
min_capacity
)
{
void
gs_matrix_assure_row_capacity
(
gs_matrix_t
*
m
,
int
row
,
int
min_capacity
)
{
row_col_t
*
the_row
=
&
m
->
rows
[
row
];
if
(
the_row
->
c_cols
<
min_capacity
)
alloc_cols
(
the_row
,
min_capacity
);
}
void
gs_matrix_trim_row_capacities
(
gs_matrix_t
*
m
)
{
void
gs_matrix_trim_row_capacities
(
gs_matrix_t
*
m
)
{
int
i
;
for
(
i
=
0
;
i
<
m
->
c_rows
;
++
i
)
{
row_col_t
*
the_row
=
&
m
->
rows
[
i
];
...
...
@@ -124,7 +132,8 @@ void gs_matrix_trim_row_capacities(gs_matrix_t *m) {
}
}
void
gs_matrix_delete_zero_entries
(
gs_matrix_t
*
m
)
{
void
gs_matrix_delete_zero_entries
(
gs_matrix_t
*
m
)
{
int
i
,
read_pos
;
for
(
i
=
0
;
i
<
m
->
c_rows
;
++
i
)
{
row_col_t
*
the_row
=
&
m
->
rows
[
i
];
...
...
@@ -139,7 +148,8 @@ void gs_matrix_delete_zero_entries(gs_matrix_t *m) {
m
->
n_zero_entries
=
0
;
}
void
gs_matrix_set
(
gs_matrix_t
*
m
,
int
row
,
int
col
,
double
val
)
{
void
gs_matrix_set
(
gs_matrix_t
*
m
,
int
row
,
int
col
,
double
val
)
{
row_col_t
*
the_row
;
col_val_t
*
cols
;
int
min
,
max
,
c
,
i
;
...
...
@@ -202,7 +212,8 @@ void gs_matrix_set(gs_matrix_t *m, int row, int col, double val) {
assert
(
c
>=
the_row
->
n_cols
-
1
||
the_row
->
cols
[
c
].
col_idx
<
the_row
->
cols
[
c
+
1
].
col_idx
);
}
double
gs_matrix_get
(
const
gs_matrix_t
*
m
,
int
row
,
int
col
)
{
double
gs_matrix_get
(
const
gs_matrix_t
*
m
,
int
row
,
int
col
)
{
row_col_t
*
the_row
;
int
c
;
...
...
@@ -231,7 +242,8 @@ double gs_matrix_get(const gs_matrix_t *m, int row, int col) {
*
* Note that the diagonal element is stored separately in this matrix implementation.
* */
double
gs_matrix_gauss_seidel
(
const
gs_matrix_t
*
m
,
double
*
x
,
int
n
)
{
double
gs_matrix_gauss_seidel
(
const
gs_matrix_t
*
m
,
double
*
x
,
int
n
)
{
double
res
=
0
.
0
;
int
r
;
...
...
@@ -278,7 +290,8 @@ void gs_matrix_export(const gs_matrix_t *m, double *nw, int size)
}
}
void
gs_matrix_dump
(
const
gs_matrix_t
*
m
,
int
a
,
int
b
,
FILE
*
out
)
{
void
gs_matrix_dump
(
const
gs_matrix_t
*
m
,
int
a
,
int
b
,
FILE
*
out
)
{
int
effective_rows
=
MIN
(
a
,
m
->
c_rows
);
int
r
,
c
,
i
;
double
*
elems
=
XMALLOCN
(
double
,
b
);
...
...
@@ -313,7 +326,8 @@ void gs_matrix_dump(const gs_matrix_t *m, int a, int b, FILE *out) {
xfree
(
elems
);
}
void
gs_matrix_self_test
(
int
d
)
{
void
gs_matrix_self_test
(
int
d
)
{
int
i
,
o
;
gs_matrix_t
*
m
=
gs_new_matrix
(
10
,
10
);
...
...
ir/adt/hungarian.c
View file @
32ea6ea0
...
...
@@ -57,7 +57,8 @@ struct _hungarian_problem_t {
DEBUG_ONLY
(
firm_dbg_module_t
*
dbg
);
};
static
void
hungarian_dump_f
(
FILE
*
f
,
int
**
C
,
int
rows
,
int
cols
,
int
width
)
{
static
void
hungarian_dump_f
(
FILE
*
f
,
int
**
C
,
int
rows
,
int
cols
,
int
width
)
{
int
i
,
j
;
fprintf
(
f
,
"
\n
"
);
...
...
@@ -71,14 +72,16 @@ static void hungarian_dump_f(FILE *f, int **C, int rows, int cols, int width) {
fprintf
(
f
,
"
\n
"
);
}
void
hungarian_print_cost_matrix
(
hungarian_problem_t
*
p
,
int
width
)
{
void
hungarian_print_cost_matrix
(
hungarian_problem_t
*
p
,
int
width
)
{
hungarian_dump_f
(
stderr
,
p
->
cost
,
p
->
num_rows
,
p
->
num_cols
,
width
);
}
/**
* Create the object and allocate memory for the data structures.
*/
hungarian_problem_t
*
hungarian_new
(
int
rows
,
int
cols
,
int
match_type
)
{
hungarian_problem_t
*
hungarian_new
(
int
rows
,
int
cols
,
int
match_type
)
{
int
i
;
hungarian_problem_t
*
p
=
XMALLOCZ
(
hungarian_problem_t
);
...
...
@@ -120,7 +123,8 @@ hungarian_problem_t *hungarian_new(int rows, int cols, int match_type) {
/**
* Prepare the cost matrix.
*/
void
hungarian_prepare_cost_matrix
(
hungarian_problem_t
*
p
,
int
mode
)
{
void
hungarian_prepare_cost_matrix
(
hungarian_problem_t
*
p
,
int
mode
)
{
int
i
,
j
;
if
(
mode
==
HUNGARIAN_MODE_MAXIMIZE_UTIL
)
{
...
...
@@ -140,7 +144,8 @@ void hungarian_prepare_cost_matrix(hungarian_problem_t *p, int mode) {
/**
* Set cost[left][right] to cost.
*/
void
hungarian_add
(
hungarian_problem_t
*
p
,
int
left
,
int
right
,
int
cost
)
{
void
hungarian_add
(
hungarian_problem_t
*
p
,
int
left
,
int
right
,
int
cost
)
{
assert
(
p
->
num_rows
>
left
&&
"Invalid row selected."
);
assert
(
p
->
num_cols
>
right
&&
"Invalid column selected."
);
assert
(
cost
>=
0
);
...
...
@@ -157,7 +162,8 @@ void hungarian_add(hungarian_problem_t *p, int left, int right, int cost) {
/**
* Set cost[left][right] to 0.
*/
void
hungarian_remv
(
hungarian_problem_t
*
p
,
int
left
,
int
right
)
{
void
hungarian_remv
(
hungarian_problem_t
*
p
,
int
left
,
int
right
)
{
assert
(
p
->
num_rows
>
left
&&
"Invalid row selected."
);
assert
(
p
->
num_cols
>
right
&&
"Invalid column selected."
);
...
...
@@ -172,7 +178,8 @@ void hungarian_remv(hungarian_problem_t *p, int left, int right) {
/**
* Frees all allocated memory.
*/
void
hungarian_free
(
hungarian_problem_t
*
p
)
{
void
hungarian_free
(
hungarian_problem_t
*
p
)
{
obstack_free
(
&
p
->
obst
,
NULL
);
xfree
(
p
);
}
...
...
@@ -180,7 +187,8 @@ void hungarian_free(hungarian_problem_t* p) {
/**
* Do the assignment.
*/
int
hungarian_solve
(
hungarian_problem_t
*
p
,
int
*
assignment
,
int
*
final_cost
,
int
cost_threshold
)
{
int
hungarian_solve
(
hungarian_problem_t
*
p
,
int
*
assignment
,
int
*
final_cost
,
int
cost_threshold
)
{
int
i
,
j
,
m
,
n
,
k
,
l
,
s
,
t
,
q
,
unmatched
,
cost
;
int
*
col_mate
;
int
*
row_mate
;
...
...
ir/adt/plist.c
View file @
32ea6ea0
...
...
@@ -39,7 +39,8 @@
* @param list the list for which to allocate the element.
* @return the newly allocated, uninitialized element.
*/
static
plist_element_t
*
allocate_element
(
plist_t
*
list
)
{
static
plist_element_t
*
allocate_element
(
plist_t
*
list
)
{
plist_element_t
*
new_element
;
if
(
list
->
first_free_element
!=
NULL
)
{
...
...
@@ -54,7 +55,8 @@ static plist_element_t *allocate_element(plist_t* list) {
return
new_element
;
}
plist_t
*
plist_new
(
void
)
{
plist_t
*
plist_new
(
void
)
{
plist_t
*
list
=
xmalloc
(
sizeof
(
*
list
)
+
sizeof
(
*
list
->
obst
));
list
->
obst
=
(
struct
obstack
*
)
&
list
[
1
];
...
...
@@ -68,7 +70,8 @@ plist_t *plist_new(void) {
return
list
;
}
plist_t
*
plist_obstack_new
(
struct
obstack
*
obst
)
{
plist_t
*
plist_obstack_new
(
struct
obstack
*
obst
)
{
plist_t
*
list
=
OALLOC
(
obst
,
plist_t
);
list
->
obst
=
obst
;
...
...
@@ -81,7 +84,8 @@ plist_t *plist_obstack_new(struct obstack *obst) {
return
list
;
}
void
plist_free
(
plist_t
*
list
)
{
void
plist_free
(
plist_t
*
list
)
{
list
->
first_element
=
NULL
;
list
->
last_element
=
NULL
;
list
->
first_free_element
=
NULL
;
...
...
@@ -93,7 +97,8 @@ void plist_free(plist_t *list) {
}
}
void
plist_insert_back
(
plist_t
*
list
,
void
*
value
)
{
void
plist_insert_back
(
plist_t
*
list
,
void
*
value
)
{
if
(
list
->
last_element
!=
NULL
)
{
plist_insert_after
(
list
,
list
->
last_element
,
value
);
}
...
...
@@ -108,7 +113,8 @@ void plist_insert_back(plist_t *list, void *value) {
}
}
void
plist_insert_front
(
plist_t
*
list
,
void
*
value
)
{
void
plist_insert_front
(
plist_t
*
list
,
void
*
value
)
{
if
(
list
->
first_element
!=
NULL
)
{
plist_insert_before
(
list
,
list
->
first_element
,
value
);
}
...
...
@@ -123,7 +129,8 @@ void plist_insert_front(plist_t *list, void *value) {
}
}
void
plist_insert_before
(
plist_t
*
list
,
plist_element_t
*
element
,
void
*
value
)
{
void
plist_insert_before
(
plist_t
*
list
,
plist_element_t
*
element
,
void
*
value
)
{
plist_element_t
*
prevElement
;
plist_element_t
*
newElement
=
allocate_element
(
list
);
...
...
@@ -143,7 +150,8 @@ void plist_insert_before(plist_t *list, plist_element_t *element, void *value) {
++
list
->
element_count
;
}
void
plist_insert_after
(
plist_t
*
list
,
plist_element_t
*
element
,
void
*
value
)
{
void
plist_insert_after
(
plist_t
*
list
,
plist_element_t
*
element
,
void
*
value
)
{
plist_element_t
*
nextElement
;
plist_element_t
*
newElement
=
allocate_element
(
list
);
...
...
@@ -163,7 +171,8 @@ void plist_insert_after(plist_t* list, plist_element_t* element, void* value) {
++
list
->
element_count
;
}
int
plist_has_value
(
plist_t
*
list
,
void
*
value
)
{
int
plist_has_value
(
plist_t
*
list
,
void
*
value
)
{
plist_element_t
*
iter
;
for
(
iter
=
plist_first
(
list
);
iter
;
iter
=
plist_element_get_next
(
iter
))
{
...
...
@@ -174,7 +183,8 @@ int plist_has_value(plist_t *list, void *value) {
return
0
;
}
plist_element_t
*
plist_find_value
(
plist_t
*
list
,
void
*
value
)
{
plist_element_t
*
plist_find_value
(
plist_t
*
list
,
void
*
value
)
{
plist_element_t
*
iter
;
for
(
iter
=
plist_first
(
list
);
iter
;
iter
=
plist_element_get_next
(
iter
))
{
...
...
@@ -185,7 +195,8 @@ plist_element_t *plist_find_value(plist_t *list, void *value) {
return
NULL
;
}
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
)
{
void
plist_erase
(
plist_t
*
list
,
plist_element_t
*
element
)
{
plist_element_t
*
next_element
=
element
->
next
;
plist_element_t
*
prev_element
=
element
->
prev
;
...
...
@@ -211,7 +222,8 @@ void plist_erase(plist_t *list, plist_element_t *element) {
list
->
first_free_element
=
element
;
}
void
plist_clear
(
plist_t
*
list
)
{
void
plist_clear
(
plist_t
*
list
)
{
plist_element_t
*
curr_element
=
list
->
first_element
;
while
(
curr_element
!=
NULL
)
{
...
...
ir/adt/pmap.c
View file @
32ea6ea0
...
...
@@ -46,7 +46,8 @@ struct pmap {
/**
* compare the keys of two entry pairs
*/
static
int
pmap_entry_cmp
(
const
void
*
p1
,
const
void
*
p2
,
size_t
size
)
{
static
int
pmap_entry_cmp
(
const
void
*
p1
,
const
void
*
p2
,
size_t
size
)
{
const
pmap_entry
*
entry1
=
p1
;
const
pmap_entry
*
entry2
=
p2
;
(
void
)
size
;
...
...
@@ -55,19 +56,23 @@ static int pmap_entry_cmp(const void *p1, const void *p2, size_t size) {
}
/* Creates a new empty map with an initial number of slots. */
pmap
*
pmap_create_ex
(
int
slots
)
{
pmap
*
pmap_create_ex
(
int
slots
)
{
return
(
pmap
*
)
new_set
(
pmap_entry_cmp
,
slots
);
}
pmap
*
pmap_create
(
void
)
{
pmap
*
pmap_create
(
void
)
{
return
pmap_create_ex
(
INITIAL_SLOTS
);
}
void
pmap_destroy
(
pmap
*
map
)
{
void
pmap_destroy
(
pmap
*
map
)
{
del_set
(
M2S
(
map
));
}
void
pmap_insert
(
pmap
*
map
,
const
void
*
key
,
void
*
value
)
{
void
pmap_insert
(
pmap
*
map
,
const
void
*
key
,
void
*
value
)
{
pmap_entry
entry
,
*
p
;
entry
.
key
=
key
;
...
...
@@ -75,32 +80,39 @@ void pmap_insert(pmap *map, const void *key, void *value) {
p
->
value
=
value
;
}
int
pmap_contains
(
pmap
*
map
,
const
void
*
key
)
{
int
pmap_contains
(
pmap
*
map
,
const
void
*
key
)
{
return
set_find
(
M2S
(
map
),
&
key
,
sizeof
(
pmap_entry
),
HASH_PTR
(
key
))
!=
NULL
;
}
pmap_entry
*
pmap_find
(
pmap
*
map
,
const
void
*
key
)
{
pmap_entry
*
pmap_find
(
pmap
*
map
,
const
void
*
key
)
{
return
(
pmap_entry
*
)
set_find
(
M2S
(
map
),
&
key
,
sizeof
(
pmap_entry
),
HASH_PTR
(
key
));
}
void
*
pmap_get
(
pmap
*
map
,
const
void
*
key
)
{
void
*
pmap_get
(
pmap
*
map
,
const
void
*
key
)
{
pmap_entry
*
entry
=
pmap_find
(
map
,
key
);
return
entry
==
NULL
?
NULL
:
entry
->
value
;
}
int
pmap_count
(
pmap
*
map
)
{
int
pmap_count
(
pmap
*
map
)
{
return
set_count
(
M2S
(
map
));
}
pmap_entry
*
pmap_first
(
pmap
*
map
)
{
pmap_entry
*
pmap_first
(
pmap
*
map
)
{
return
(
pmap_entry
*
)
set_first
(
M2S
(
map
));
}
pmap_entry
*
pmap_next
(
pmap
*
map
)
{
pmap_entry
*
pmap_next
(
pmap
*
map
)
{
return
(
pmap_entry
*
)
set_next
(
M2S
(
map
));
}
void
pmap_break
(
pmap
*
map
)
{
void
pmap_break
(
pmap
*
map
)
{
set_break
(
M2S
(
map
));
}
ir/adt/pqueue.c
View file @
32ea6ea0
...
...
@@ -58,7 +58,8 @@ struct _pqueue_t {
* Enforces the heap characteristics if the queue
* starting from element at position @p pos.
*/
static
void
pqueue_heapify
(
pqueue_t
*
q
,
unsigned
pos
)
{
static
void
pqueue_heapify
(
pqueue_t
*
q
,
unsigned
pos
)
{
unsigned
len
=
ARR_LEN
(
q
->
elems
);
while
(
pos
*
2
<
len
)
{
...
...
@@ -88,7 +89,8 @@ static void pqueue_heapify(pqueue_t *q, unsigned pos) {
/**
* Sifts up a newly inserted element at position @p pos.
*/
static
void
pqueue_sift_up
(
pqueue_t
*
q
,
unsigned
pos
)
{
static
void
pqueue_sift_up
(
pqueue_t
*
q
,
unsigned
pos
)
{
while
(
q
->
elems
[
pos
].
priority
>
q
->
elems
[
pos
/
2
].
priority
)
{
pqueue_el_t
tmp
;
...
...
@@ -100,18 +102,21 @@ static void pqueue_sift_up(pqueue_t *q, unsigned pos) {
}
}
pqueue_t
*
new_pqueue
(
void
)
{
pqueue_t
*
new_pqueue
(
void
)
{
pqueue_t
*
res
=
XMALLOC
(
pqueue_t
);
res
->
elems
=
NEW_ARR_F
(
pqueue_el_t
,
0
);
return
res
;
}
void
del_pqueue
(
pqueue_t
*
q
)
{
void
del_pqueue
(
pqueue_t
*
q
)
{
DEL_ARR_F
(
q
->
elems
);
free
(
q
);
}
void
pqueue_put
(
pqueue_t
*
q
,
void
*
data
,
int
priority
)
{
void
pqueue_put
(
pqueue_t
*
q
,
void
*
data
,
int
priority
)
{
pqueue_el_t
el
;
el
.
data
=
data
;
...
...
@@ -122,7 +127,8 @@ void pqueue_put(pqueue_t *q, void *data, int priority) {
pqueue_sift_up
(
q
,
ARR_LEN
(
q
->
elems
)
-
1
);
}
void
*
pqueue_pop_front
(
pqueue_t
*
q
)
{
void
*
pqueue_pop_front
(
pqueue_t
*
q
)
{
switch
(
ARR_LEN
(
q
->
elems
))
{
case
0
:
assert
(
0
&&
"Attempt to retrieve element from empty priority queue."
);
...
...
@@ -145,10 +151,12 @@ void *pqueue_pop_front(pqueue_t *q) {
}
}
int
pqueue_length
(
const
pqueue_t
*
q
)
{
int
pqueue_length
(
const
pqueue_t
*
q
)
{
return
ARR_LEN
(
q
->
elems
);
}
int
pqueue_empty
(
const
pqueue_t
*
q
)
{
int
pqueue_empty
(
const
pqueue_t
*
q