提交 ab4514d1 authored 作者: Anthony Minessale's avatar Anthony Minessale

fix indenting

上级 3947d443
......@@ -134,11 +134,11 @@
* mpool_resize only.
*/
typedef void (*mpool_log_func_t)(const void *mp_p,
const int func_id,
const unsigned long byte_size,
const unsigned long ele_n,
const void *old_addr, const void *new_addr,
const unsigned long old_byte_size);
const int func_id,
const unsigned long byte_size,
const unsigned long ele_n,
const void *old_addr, const void *new_addr,
const unsigned long old_byte_size);
#ifdef MPOOL_MAIN
......@@ -183,7 +183,7 @@ typedef void mpool_t;
*/
extern
mpool_t *mpool_open(const unsigned int flags, const unsigned int page_size,
void *start_addr, int *error_p);
void *start_addr, int *error_p);
/*
* int mpool_close
......@@ -251,7 +251,7 @@ int mpool_clear(mpool_t *mp_p);
*/
extern
void *mpool_alloc(mpool_t *mp_p, const unsigned long byte_size,
int *error_p);
int *error_p);
/*
* void *mpool_calloc
......@@ -281,7 +281,7 @@ void *mpool_alloc(mpool_t *mp_p, const unsigned long byte_size,
*/
extern
void *mpool_calloc(mpool_t *mp_p, const unsigned long ele_n,
const unsigned long ele_size, int *error_p);
const unsigned long ele_size, int *error_p);
/*
* int mpool_free
......@@ -341,9 +341,9 @@ int mpool_free(mpool_t *mp_p, void *addr, const unsigned long size);
*/
extern
void *mpool_resize(mpool_t *mp_p, void *old_addr,
const unsigned long old_byte_size,
const unsigned long new_byte_size,
int *error_p);
const unsigned long old_byte_size,
const unsigned long new_byte_size,
int *error_p);
/*
* int mpool_stats
......@@ -381,10 +381,10 @@ void *mpool_resize(mpool_t *mp_p, void *old_addr,
*/
extern
int mpool_stats(const mpool_t *mp_p, unsigned int *page_size_p,
unsigned long *num_alloced_p,
unsigned long *user_alloced_p,
unsigned long *max_alloced_p,
unsigned long *tot_alloced_p);
unsigned long *num_alloced_p,
unsigned long *user_alloced_p,
unsigned long *max_alloced_p,
unsigned long *tot_alloced_p);
/*
* int mpool_set_log_func
......@@ -461,3 +461,14 @@ const char *mpool_strerror(const int error);
/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
#endif /* ! __MPOOL_H__ */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
......@@ -83,25 +83,25 @@
* were about 2^68 hashes to choose from. I only tested about a
* billion of those.
*/
#define HASH_MIX(a, b, c) \
do { \
a -= b; a -= c; a ^= (c >> 13); \
b -= c; b -= a; b ^= (a << 8); \
c -= a; c -= b; c ^= (b >> 13); \
a -= b; a -= c; a ^= (c >> 12); \
b -= c; b -= a; b ^= (a << 16); \
c -= a; c -= b; c ^= (b >> 5); \
a -= b; a -= c; a ^= (c >> 3); \
b -= c; b -= a; b ^= (a << 10); \
c -= a; c -= b; c ^= (b >> 15); \
} while(0)
#define SET_POINTER(pnt, val) \
do { \
if ((pnt) != NULL) { \
(*(pnt)) = (val); \
} \
} while(0)
#define HASH_MIX(a, b, c) \
do { \
a -= b; a -= c; a ^= (c >> 13); \
b -= c; b -= a; b ^= (a << 8); \
c -= a; c -= b; c ^= (b >> 13); \
a -= b; a -= c; a ^= (c >> 12); \
b -= c; b -= a; b ^= (a << 16); \
c -= a; c -= b; c ^= (b >> 5); \
a -= b; a -= c; a ^= (c >> 3); \
b -= c; b -= a; b ^= (a << 10); \
c -= a; c -= b; c ^= (b >> 15); \
} while(0)
#define SET_POINTER(pnt, val) \
do { \
if ((pnt) != NULL) { \
(*(pnt)) = (val); \
} \
} while(0)
/*
* The following macros take care of the mmap case. When we are
......@@ -117,9 +117,9 @@
#else
#define TABLE_POINTER(tab_p, type, pnt) \
((tab_p)->ta_mmap == NULL || (pnt) == NULL ? (pnt) : \
(type)((char *)((tab_p)->ta_mmap) + (long)(pnt)))
#define TABLE_POINTER(tab_p, type, pnt) \
((tab_p)->ta_mmap == NULL || (pnt) == NULL ? (pnt) : \
(type)((char *)((tab_p)->ta_mmap) + (long)(pnt)))
#endif
......@@ -127,8 +127,8 @@
* Macros to get at the key and the data pointers
*/
#define ENTRY_KEY_BUF(entry_p) ((entry_p)->te_key_buf)
#define ENTRY_DATA_BUF(tab_p, entry_p) \
(ENTRY_KEY_BUF(entry_p) + (entry_p)->te_key_size)
#define ENTRY_DATA_BUF(tab_p, entry_p) \
(ENTRY_KEY_BUF(entry_p) + (entry_p)->te_key_size)
/*
* Table structures...
......@@ -142,10 +142,10 @@
* faster.
*/
typedef struct table_shell_st {
unsigned int te_key_size; /* size of data */
unsigned int te_data_size; /* size of data */
struct table_shell_st *te_next_p; /* pointer to next in the list */
/* NOTE: this does not have the te_key_buf field here */
unsigned int te_key_size; /* size of data */
unsigned int te_data_size; /* size of data */
struct table_shell_st *te_next_p; /* pointer to next in the list */
/* NOTE: this does not have the te_key_buf field here */
} table_shell_t;
/*
......@@ -157,10 +157,10 @@ typedef struct table_shell_st {
* changed to match.
*/
typedef struct table_entry_st {
unsigned int te_key_size; /* size of data */
unsigned int te_data_size; /* size of data */
struct table_entry_st *te_next_p; /* pointer to next in the list */
unsigned char te_key_buf[1]; /* 1st byte of key buf */
unsigned int te_key_size; /* size of data */
unsigned int te_data_size; /* size of data */
struct table_entry_st *te_next_p; /* pointer to next in the list */
unsigned char te_key_buf[1]; /* 1st byte of key buf */
} table_entry_t;
/* external structure for debuggers be able to see void */
......@@ -168,20 +168,20 @@ typedef table_entry_t table_entry_ext_t;
/* main table structure */
typedef struct table_st {
unsigned int ta_magic; /* magic number */
unsigned int ta_flags; /* table's flags defined in table.h */
unsigned int ta_bucket_n; /* num of buckets, should be 2^X */
unsigned int ta_entry_n; /* num of entries in all buckets */
unsigned int ta_data_align; /* data alignment value */
table_entry_t **ta_buckets; /* array of linked lists */
table_linear_t ta_linear; /* linear tracking */
struct table_st *ta_mmap; /* mmaped table */
unsigned long ta_file_size; /* size of on-disk space */
unsigned int ta_magic; /* magic number */
unsigned int ta_flags; /* table's flags defined in table.h */
unsigned int ta_bucket_n; /* num of buckets, should be 2^X */
unsigned int ta_entry_n; /* num of entries in all buckets */
unsigned int ta_data_align; /* data alignment value */
table_entry_t **ta_buckets; /* array of linked lists */
table_linear_t ta_linear; /* linear tracking */
struct table_st *ta_mmap; /* mmaped table */
unsigned long ta_file_size; /* size of on-disk space */
void *ta_mem_pool; /* pointer to some memory pool */
table_mem_alloc_t ta_alloc_func; /* memory allocation function */
table_mem_resize_t ta_resize_func; /* memory resize function */
table_mem_free_t ta_free_func; /* memory free function */
void *ta_mem_pool; /* pointer to some memory pool */
table_mem_alloc_t ta_alloc_func; /* memory allocation function */
table_mem_resize_t ta_resize_func; /* memory resize function */
table_mem_free_t ta_free_func; /* memory free function */
} table_t;
/* external table structure for debuggers */
......@@ -189,41 +189,53 @@ typedef table_t table_ext_t;
/* local comparison functions */
typedef int (*compare_t)(const void *element1_p, const void *element2_p,
table_compare_t user_compare,
const table_t *table_p, int *err_bp);
table_compare_t user_compare,
const table_t *table_p, int *err_bp);
/*
* to map error to string
*/
typedef struct {
int es_error; /* error number */
char *es_string; /* assocaited string */
int es_error; /* error number */
char *es_string; /* assocaited string */
} error_str_t;
static error_str_t errors[] = {
{ TABLE_ERROR_NONE, "no error" },
{ TABLE_ERROR_PNT, "invalid table pointer" },
{ TABLE_ERROR_ARG_NULL, "buffer argument is null" },
{ TABLE_ERROR_SIZE, "incorrect size argument" },
{ TABLE_ERROR_OVERWRITE, "key exists and no overwrite" },
{ TABLE_ERROR_NOT_FOUND, "key does not exist" },
{ TABLE_ERROR_ALLOC, "error allocating memory" },
{ TABLE_ERROR_LINEAR, "linear access not in progress" },
{ TABLE_ERROR_OPEN, "could not open file" },
{ TABLE_ERROR_SEEK, "could not seek to position in file" },
{ TABLE_ERROR_READ, "could not read from file" },
{ TABLE_ERROR_WRITE, "could not write to file" },
{ TABLE_ERROR_MMAP_NONE, "no mmap support compiled in library" },
{ TABLE_ERROR_MMAP, "could not mmap the file" },
{ TABLE_ERROR_MMAP_OP, "operation not valid on mmap files" },
{ TABLE_ERROR_EMPTY, "table is empty" },
{ TABLE_ERROR_NOT_EMPTY, "table contains data" },
{ TABLE_ERROR_ALIGNMENT, "invalid alignment value" },
{ TABLE_ERROR_COMPARE, "problems with internal comparison" },
{ TABLE_ERROR_FREE, "memory free error" },
{ 0 }
{ TABLE_ERROR_NONE, "no error" },
{ TABLE_ERROR_PNT, "invalid table pointer" },
{ TABLE_ERROR_ARG_NULL, "buffer argument is null" },
{ TABLE_ERROR_SIZE, "incorrect size argument" },
{ TABLE_ERROR_OVERWRITE, "key exists and no overwrite" },
{ TABLE_ERROR_NOT_FOUND, "key does not exist" },
{ TABLE_ERROR_ALLOC, "error allocating memory" },
{ TABLE_ERROR_LINEAR, "linear access not in progress" },
{ TABLE_ERROR_OPEN, "could not open file" },
{ TABLE_ERROR_SEEK, "could not seek to position in file" },
{ TABLE_ERROR_READ, "could not read from file" },
{ TABLE_ERROR_WRITE, "could not write to file" },
{ TABLE_ERROR_MMAP_NONE, "no mmap support compiled in library" },
{ TABLE_ERROR_MMAP, "could not mmap the file" },
{ TABLE_ERROR_MMAP_OP, "operation not valid on mmap files" },
{ TABLE_ERROR_EMPTY, "table is empty" },
{ TABLE_ERROR_NOT_EMPTY, "table contains data" },
{ TABLE_ERROR_ALIGNMENT, "invalid alignment value" },
{ TABLE_ERROR_COMPARE, "problems with internal comparison" },
{ TABLE_ERROR_FREE, "memory free error" },
{ 0 }
};
#define INVALID_ERROR "invalid error code"
#endif /* ! __TABLE_LOC_H__ */
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
差异被折叠。
......@@ -26,12 +26,12 @@
#include <errno.h> /* for setting errno */
#include <sys/types.h>
#ifndef _WIN32
/* not in Windows! */
/* not in Windows! */
# include <unistd.h>
# include <stdint.h>
#endif
#ifndef SIMCLIST_NO_DUMPRESTORE
/* includes for dump/restore */
/* includes for dump/restore */
# include <time.h>
# include <sys/uio.h> /* for READ_ERRCHECK() and write() */
# include <fcntl.h> /* for open() etc */
......@@ -88,31 +88,31 @@ typedef INT64 int64_t;
/* define some commodity macros for Dump/Restore functionality */
#ifndef SIMCLIST_NO_DUMPRESTORE
/* write() decorated with error checking logic */
#define WRITE_ERRCHECK(fd, msgbuf, msglen) do { \
if (write(fd, msgbuf, msglen) < 0) return -1; \
} while (0);
#define WRITE_ERRCHECK(fd, msgbuf, msglen) do { \
if (write(fd, msgbuf, msglen) < 0) return -1; \
} while (0);
/* READ_ERRCHECK() decorated with error checking logic */
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
if (read(fd, msgbuf, msglen) != msglen) { \
/*errno = EPROTO;*/ \
return -1; \
} \
} while (0);
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
if (read(fd, msgbuf, msglen) != msglen) { \
/*errno = EPROTO;*/ \
return -1; \
} \
} while (0);
/* convert 64bit integers from host to network format */
#define hton64(x) (\
htons(1) == 1 ? \
(uint64_t)x /* big endian */ \
: /* little endian */ \
((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \
)
#define hton64(x) ( \
htons(1) == 1 ? \
(uint64_t)x /* big endian */ \
: /* little endian */ \
((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \
)
/* convert 64bit integers from network to host format */
#define ntoh64(x) (hton64(x))
......@@ -206,12 +206,12 @@ static int list_attrOk(const list_t *restrict l);
/* do not inline, this is recursive */
static void list_sort_quicksort(list_t *restrict l, int versus,
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel);
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel);
static inline void list_sort_selectionsort(list_t *restrict l, int versus,
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel);
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel);
static void *list_get_minmax(const list_t *restrict l, int versus);
......@@ -792,8 +792,8 @@ static void *list_sort_quicksort_threadwrapper(void *wrapped_params) {
#endif
static inline void list_sort_selectionsort(list_t *restrict l, int versus,
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel) {
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel) {
struct list_entry_s *cursor, *toswap, *firstunsorted;
void *tmpdata;
......@@ -813,8 +813,8 @@ static inline void list_sort_selectionsort(list_t *restrict l, int versus,
}
static void list_sort_quicksort(list_t *restrict l, int versus,
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel) {
unsigned int first, struct list_entry_s *fel,
unsigned int last, struct list_entry_s *lel) {
unsigned int pivotid;
unsigned int i;
register struct list_entry_s *pivot;
......@@ -1094,15 +1094,15 @@ int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict
/**** DUMP FORMAT ****
[ ver timestamp | totlen numels elemlen hash | DATA ]
[ ver timestamp | totlen numels elemlen hash | DATA ]
where DATA can be:
@ for constant-size list (element size is constant; elemlen > 0)
[ elem elem ... elem ]
@ for other lists (element size dictated by element_meter each time; elemlen <= 0)
[ size elem size elem ... size elem ]
where DATA can be:
@ for constant-size list (element size is constant; elemlen > 0)
[ elem elem ... elem ]
@ for other lists (element size dictated by element_meter each time; elemlen <= 0)
[ size elem size elem ... size elem ]
all integers are encoded in NETWORK BYTE FORMAT
all integers are encoded in NETWORK BYTE FORMAT
*****/
......@@ -1327,10 +1327,10 @@ int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len
/* possibly verify the list consistency */
/* wrt hash */
/* don't do that
if (header.listhash != 0 && header.listhash != list_hash(l)) {
errno = ECANCELED;
return -1;
}
if (header.listhash != 0 && header.listhash != list_hash(l)) {
errno = ECANCELED;
return -1;
}
*/
/* wrt header */
......@@ -1487,14 +1487,14 @@ static int list_repOk(const list_t *restrict l) {
struct list_entry_s *s;
ok = (l != NULL) && (
/* head/tail checks */
(l->head_sentinel != NULL && l->tail_sentinel != NULL) &&
(l->head_sentinel != l->tail_sentinel) && (l->head_sentinel->prev == NULL && l->tail_sentinel->next == NULL) &&
/* empty list */
(l->numels > 0 || (l->mid == NULL && l->head_sentinel->next == l->tail_sentinel && l->tail_sentinel->prev == l->head_sentinel)) &&
/* spare elements checks */
l->spareelsnum <= SIMCLIST_MAX_SPARE_ELEMS
);
/* head/tail checks */
(l->head_sentinel != NULL && l->tail_sentinel != NULL) &&
(l->head_sentinel != l->tail_sentinel) && (l->head_sentinel->prev == NULL && l->tail_sentinel->next == NULL) &&
/* empty list */
(l->numels > 0 || (l->mid == NULL && l->head_sentinel->next == l->tail_sentinel && l->tail_sentinel->prev == l->head_sentinel)) &&
/* spare elements checks */
l->spareelsnum <= SIMCLIST_MAX_SPARE_ELEMS
);
if (!ok) return 0;
......@@ -1523,3 +1523,13 @@ static int list_attrOk(const list_t *restrict l) {
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论