Last change
on this file since 478dade was
ac4dad2,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
shorten experimental code
|
-
Property mode set to
100644
|
File size:
782 bytes
|
Line | |
---|
1 | #include <stdlib.h> |
---|
2 | #include "c-pair.h" |
---|
3 | |
---|
4 | pair * new_pair( void * first, void * second ) { |
---|
5 | pair * p = malloc( sizeof(pair) ); /***/ |
---|
6 | *p = (pair){ first, second }; /***/ |
---|
7 | return p; |
---|
8 | } |
---|
9 | |
---|
10 | pair * copy_pair( const pair * src, |
---|
11 | void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) { |
---|
12 | return new_pair( copy_first(src->first), copy_second(src->second) ); |
---|
13 | } |
---|
14 | |
---|
15 | void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)) { |
---|
16 | free_first( p->first ); |
---|
17 | free_second( p->second ); |
---|
18 | free( p ); |
---|
19 | } |
---|
20 | |
---|
21 | int cmp_pair( const pair * a, const pair * b, |
---|
22 | int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)) { |
---|
23 | int c = cmp_first( a->first, b->first ); |
---|
24 | if ( c == 0 ) c = cmp_second( a->second, b->second ); |
---|
25 | return c; |
---|
26 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.