Main Page Modules Data Structures File List Data Fields Globals Related Pages

# rpmdb/merge.c File Reference

`#include "system.h"`

Go to the source code of this file.

## Defines
#define | NATURAL
#define | THRESHOLD 16
#define | ISIZE sizeof(int)
#define | PSIZE sizeof(unsigned char *)
#define | ICOPY_LIST(src, dst, last)
#define | ICOPY_ELT(src, dst, i)
#define | CCOPY_LIST(src, dst, last)
#define | CCOPY_ELT(src, dst, i)
#define | EVAL(p)
#define | swap(a, b)
#define | reverse(bot, top)
## Functions
void | insertionsort (unsigned char *a, size_t n, size_t size, int(*cmp)(const void *, const void *))
void | setup (unsigned char *list1, unsigned char *list2, size_t n, size_t size, int(*cmp)(const void *, const void *))
int | mergesort (void *base, size_t nmemb, size_t size, int(*cmp)(const void *, const void *))
| Mergesort, same arguments as qsort(2). More...

## Define Documentation

#define CCOPY_ELT | ( | src,
|  | dst,
|  | i |  | ) |

| Value:
    do                                      \
                    *dst++ = *src++;                \
            while (i -= 1)
Definition at line 73 of file merge.c. Referenced by mergesort.

#define CCOPY_LIST | ( | src,
|  | dst,
|  | last |  | ) |

| Value:
    do                                      \
                    *dst++ = *src++;                \
            while (src < last)
Definition at line 69 of file merge.c. Referenced by mergesort.

#define EVAL | ( | p |  | ) |

| Value:
    (unsigned char **)                                      \
        ((unsigned char *)0 +                                               \
            (((unsigned char *)p + PSIZE - 1 - (unsigned char *) 0) & ~(PSIZE - 1)))
Definition at line 84 of file merge.c. Referenced by mergesort, and setup.

#define ICOPY_ELT | ( | src,
|  | dst,
|  | i |  | ) |

| Value:
    do                                                      \
            *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE;  \
            while (i -= ISIZE)
Definition at line 64 of file merge.c. Referenced by mergesort.

#define ICOPY_LIST | ( | src,
|  | dst,
|  | last |  | ) |

| Value:
    do                                                      \
            *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE;    \
            while(src < last)
Definition at line 60 of file merge.c. Referenced by mergesort.

#define ISIZE sizeof(int)

| Definition at line 58 of file merge.c. Referenced by mergesort.

#define NATURAL

| Definition at line 49 of file merge.c.

#define PSIZE sizeof(unsigned char *)

| Definition at line 59 of file merge.c. Referenced by mergesort.

#define reverse | ( | bot,
|  | top |  | ) |

| Value:
    {                               \
            s = top;                                        \
            do {                                            \
                    i = size;                               \
                    do {                                    \
                            tmp = *bot; *bot++ = *s; *s++ = tmp; \
                    } while (--i);                          \
                    s -= size2;                             \
            } while(bot < s);                               \
    }
Definition at line 96 of file merge.c. Referenced by setup.

#define swap | ( | a,
|  | b |  | ) |

| Value:
    {                                       \
                    s = b;                                  \
                    i = size;                               \
                    do {                                    \
                            tmp = *a; *a++ = *s; *s++ = tmp; \
                    } while (--i);                          \
                    a -= size;                              \
            }
Definition at line 88 of file merge.c. Referenced by insertionsort, and setup.

#define THRESHOLD 16

| Definition at line 50 of file merge.c. Referenced by setup.

## Function Documentation

void insertionsort | ( | unsigned char * | a,
|  | size_t | n,
|  | size_t | size,
|  | int(* | cmp)(const void *, const void *)
| ) | `[static]`

| Definition at line 112 of file merge.c. References swap. Referenced by setup.

int mergesort | ( | void * | base,
|  | size_t | nmemb,
|  | size_t | size,
|  | int(* | cmp)(const void *, const void *)
| ) |

| Mergesort, same arguments as qsort(2). Definition at line 207 of file merge.c. References CCOPY_ELT, CCOPY_LIST, errno, EVAL, ICOPY_ELT, ICOPY_LIST, ISIZE, PSIZE, and setup.

void setup | ( | unsigned char * | list1,
|  | unsigned char * | list2,
|  | size_t | n,
|  | size_t | size,
|  | int(* | cmp)(const void *, const void *)
| ) | `[static]`

| Definition at line 135 of file merge.c. References EVAL, insertionsort, reverse, swap, and THRESHOLD. Referenced by mergesort.