ADT
arm-eh
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since 5c2b454 was f4e3419d, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago |
restructure paper documents
|
-
Property mode
set to
100644
|
File size:
803 bytes
|
Line | |
---|
1 | #include <stdlib.h>
|
---|
2 | #include "c-pair.h"
|
---|
3 |
|
---|
4 | struct pair* new_pair(void* first, void* second) {
|
---|
5 | struct pair* p = malloc(sizeof(struct pair)); /***/
|
---|
6 | *p = (struct pair){ first, second }; /***/
|
---|
7 | return p;
|
---|
8 | }
|
---|
9 |
|
---|
10 | struct pair* copy_pair(const struct 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(struct 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 struct pair* a, const struct 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.