source: doc/papers/general/evaluation/c-pair.c @ 0f9e6b20

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 0f9e6b20 was 604e76d, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

initial setup for general and concurrency papers

  • Property mode set to 100644
File size: 803 bytes
RevLine 
[604e76d]1#include <stdlib.h>
2#include "c-pair.h"
3
4struct 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
10struct 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
15void 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
21int 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.