123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- typedef enum {
- TRP_POS_S = 0,
- TRP_POS_P = 1,
- TRP_POS_O = 2,
- } LSUP_TriplePos;
- typedef enum {
- LSUP_BUF_BORROWED = 1<<0,
- } LSUP_BufferFlag;
- typedef struct LSUP_Buffer {
- unsigned char *addr;
- size_t size;
- LSUP_BufferFlag flags;
- } LSUP_Buffer;
- typedef struct buffer_triple_t {
- LSUP_Buffer *s;
- LSUP_Buffer *p;
- LSUP_Buffer *o;
- } LSUP_BufferTriple;
- LSUP_rc
- LSUP_buffer_init (
- LSUP_Buffer *buf, const size_t size, const unsigned char *data);
- inline LSUP_Buffer *
- LSUP_buffer_new (const unsigned char *data, const size_t size)
- {
- LSUP_Buffer *buf;
- CALLOC_GUARD (buf, NULL);
- if (LSUP_buffer_init (buf, size, data) != LSUP_OK) {
- free (buf->addr);
- free (buf);
- return NULL;
- }
- return buf;
- }
- inline LSUP_Buffer *
- LSUP_buffer_new_borrowed (unsigned char *data, const size_t size)
- {
- LSUP_Buffer *buf;
- MALLOC_GUARD (buf, NULL);
- buf->addr = data;
- buf->size = size;
- buf->flags = LSUP_BUF_BORROWED;
- return buf;
- }
- void LSUP_buffer_done (LSUP_Buffer *buf);
- void LSUP_buffer_free (LSUP_Buffer *buf);
- inline LSUP_Key
- LSUP_buffer_hash (const LSUP_Buffer *buf)
- {
- return (buf == NULL) ? NULL_KEY :
- LSUP_HASH (buf->addr, buf->size, LSUP_HASH_SEED);
- }
- void LSUP_buffer_print (const LSUP_Buffer *buf);
- char *
- LSUP_buffer_as_str (const LSUP_Buffer *buf);
- inline int LSUP_buffer_cmp (const LSUP_Buffer *buf1, const LSUP_Buffer *buf2)
- {
- return memcmp (
- buf1->addr, buf2->addr,
- (buf1->size > buf2->size ? buf1->size : buf2->size));
- }
- inline bool LSUP_buffer_eq (const LSUP_Buffer *buf1, const LSUP_Buffer *buf2)
- {
- if (buf1->size != buf2->size) return false;
- return (LSUP_buffer_cmp (buf1, buf2) == 0) ? true : false;
- }
- LSUP_BufferTriple *
- LSUP_btriple_new(LSUP_Buffer *s, LSUP_Buffer *p, LSUP_Buffer *o);
- LSUP_rc
- LSUP_btriple_init (
- LSUP_BufferTriple *sspo,
- LSUP_Buffer *s, LSUP_Buffer *p, LSUP_Buffer *o);
- void
- LSUP_btriple_done (LSUP_BufferTriple *sspo);
- void
- LSUP_btriple_free (LSUP_BufferTriple *sspo);
- inline LSUP_Buffer *
- LSUP_btriple_pos (const LSUP_BufferTriple *btrp, LSUP_TriplePos n)
- {
- if (n == TRP_POS_S) return btrp->s;
- if (n == TRP_POS_P) return btrp->p;
- if (n == TRP_POS_O) return btrp->o;
- return NULL;
- }
- inline LSUP_Key
- LSUP_btriple_hash (const LSUP_BufferTriple *strp)
- {
- return LSUP_HASH (
- strp->s->addr, strp->s->size,
- LSUP_HASH (
- strp->p->addr, strp->p->size,
- LSUP_HASH (strp->o->addr, strp->o->size, LSUP_HASH_SEED)
- )
- );
- }
|