| Last change
 on this file since 3da5885 was             ac4dad2, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago | 
        
          | 
shorten experimental code
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            782 bytes | 
      
      
| Rev | Line |  | 
|---|
| [604e76d] | 1 | #include <stdlib.h> | 
|---|
|  | 2 | #include "c-pair.h" | 
|---|
|  | 3 |  | 
|---|
| [ac4dad2] | 4 | pair * new_pair( void * first, void * second ) { | 
|---|
|  | 5 | pair * p = malloc( sizeof(pair) ); /***/ | 
|---|
|  | 6 | *p = (pair){ first, second }; /***/ | 
|---|
| [604e76d] | 7 | return p; | 
|---|
|  | 8 | } | 
|---|
|  | 9 |  | 
|---|
| [ac4dad2] | 10 | pair * copy_pair( const pair * src, | 
|---|
|  | 11 | void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) { | 
|---|
| [604e76d] | 12 | return new_pair( copy_first(src->first), copy_second(src->second) ); | 
|---|
|  | 13 | } | 
|---|
|  | 14 |  | 
|---|
| [ac4dad2] | 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 ); | 
|---|
| [604e76d] | 19 | } | 
|---|
|  | 20 |  | 
|---|
| [ac4dad2] | 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 ); | 
|---|
| [604e76d] | 25 | return c; | 
|---|
|  | 26 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.