Simple data structures / objects in plain C Snapshot
Functions
dlistunr.c File Reference
#include <cutils/dlistunr.h>

Go to the source code of this file.

Functions

M_INLINE DLISTUNR_entryDLISTUNR_new_list_entry (size_t datasize)
M_INLINE void * DLISTUNR_insert_entry (DLISTUNR_entry *entry, size_t pos, size_t elmmaxcount, size_t elmsize)
M_INLINE void * DLISTUNR_insert_newnode (DLISTUNR *list, DLISTUNR_position insert_pos)
int DLISTUNR_insert_after (DLISTUNR *list, DLISTUNR_position pos, void *data, size_t size)
 insert new entry after a given entry into this unrolled linked list
int DLISTUNR_unlink (DLISTUNR *list, DLISTUNR_position pos)
 delete an element from a unrolled list.

Function Documentation

M_INLINE void* DLISTUNR_insert_entry ( DLISTUNR_entry entry,
size_t  pos,
size_t  elmmaxcount,
size_t  elmsize 
)

Definition at line 16 of file dlistunr.c.

{
        if (!entry) {
                return 0;
        }

        if (entry->elmcount >= elmmaxcount || entry->elmcount == (size_t) -1) {
                return 0;
        }

        pos ++;

        if (pos < entry->elmcount) {    
                memmove(entry->buffer + (pos + 1) * elmsize,
                            entry->buffer +  pos * elmsize, 
                                (entry->elmcount - pos) * elmsize);
                
        } 
        
        entry->elmcount ++ ;
        return entry->buffer + (pos * elmsize);
}
M_INLINE void* DLISTUNR_insert_newnode ( DLISTUNR list,
DLISTUNR_position  insert_pos 
)

Definition at line 39 of file dlistunr.c.

{
        DLISTUNR_entry *newnode;

        newnode = DLISTUNR_new_list_entry( list->elmsize * list->elmmaxcount);
        if (!newnode) {
                return 0;
        }
        
        DRING_insert_after( (DRING *) insert_pos.entry, (DRING *) newnode );

        newnode->elmcount = 1;
        return newnode->buffer;
}
M_INLINE DLISTUNR_entry* DLISTUNR_new_list_entry ( size_t  datasize)

Definition at line 3 of file dlistunr.c.

{
        DLISTUNR_entry *entry;

        entry = malloc(  sizeof(DLISTUNR_entry) + datasize );
        if (!entry) {
                return 0;
        }
        entry->elmcount = 0;
        return entry;
}