IBList.xcc

Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com)

Copyright 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.

This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.

The IBList implements a blocked list of same-sized items.

IBList— List of inlined items in blocked storage.
struct IBList_ {
  //@args       Memory memory, size_t itemSize, int32_t blocking
  size_t BLOCKING;
  size_t ITEMSIZE;
  IBListItem FIRSTITEM;
  IBListItem PAST;
  IDList_ BLOCKLIST_;
  //@access BLOCKLIST   IBList__BLOCKLIST_(this)
  //@access FIRSTBLOCK  (IBListBlock)IDList_firstItem(IBList_BLOCKLIST(this))
  //@access LASTBLOCK  (IBListBlock)IDList_lastItem(IBList_BLOCKLIST(this))
  //@access MEMORY      IDList_memory(IBList_BLOCKLIST(this))
};
IBList_empty— Empty this IBList.
void
IBList_empty(IBList this, IBListItemRelease release);
IBList_memory— This IBList memory.
static inline Memory
IBList_memory(const_IBList this)
{
  return IBList_MEMORY(this);
}
IBList_blocking— This IBList block factor.
static inline size_t
IBList_blocking(const_IBList this)
{
  return IBList_BLOCKING(this);
}
IBList_itemSize— Size in bytes of an IBList item.
static inline size_t
IBList_itemSize(const_IBList this)
{
  return IBList_ITEMSIZE(this);
}
IBList_firstItem— This IBList first item.
static inline IBListItem
IBList_firstItem(const_IBList this)
{
  return IBList_FIRSTITEM(this);
}
IBList_past— This IBList past item.
static inline IBListItem
IBList_past(const_IBList this)
{
  return IBList_PAST(this);
}
IBList_firstBlock— This IBList first IBListBlock.
static inline IBListBlock
IBList_firstBlock(const_IBList this)
{
  return IBList_FIRSTBLOCK(this);
}
IBList_lastBlock— This IBList last IBListBlock.
static inline IBListBlock
IBList_lastBlock(const_IBList this)
{
  return IBList_LASTBLOCK(this);
}
IBList_isEmpty— True iff this IBList is empty.
static inline bool
IBList_isEmpty(const_IBList this)
{
  char *firstItem = IBList_FIRSTITEM(this);
  char *past = IBList_PAST(this);
  return past == firstItem;
}
IBList_isSingle— True iff this IBList has a single entry.
static inline bool
IBList_isSingle(const_IBList this)
{
  size_t itemSize = IBList_ITEMSIZE(this);
  char *firstItem = IBList_FIRSTITEM(this);
  char *past = IBList_PAST(this);
  char *lastItem = past - itemSize;
  return firstItem == lastItem;
}
IBList_count— Count items in the IBList.
Return
The count of items in the IBList.
static inline int32_t
IBList_count(const_IBList this)
{
  size_t itemSize = IBList_ITEMSIZE(this);
  int32_t blocking = IBList_BLOCKING(this);
  const_IDList blockList = IBList_BLOCKLIST(this);
  int32_t count = (IDList_count(blockList) - 1)*blocking;
  char *lastBlock = IBList_LASTBLOCK(this);
  char *firstItem = IBList_FIRSTITEM(this);
  char *past = IBList_PAST(this);
  if (past == firstItem) return 0;
  return count + (past - lastBlock)/itemSize;
}
IBList_lastItem— Last item of the IBList.
Return
Pointer to the last item.
static inline IBListItem
IBList_lastItem(const_IBList this)
{
  size_t itemSize = IBList_ITEMSIZE(this);
  char *past = IBList_PAST(this);
  char *lastItem = past - itemSize;
  Except_REQUIRE(!IBList_isEmpty(this));
  return lastItem;
}
IBList_BOT— Dereference bottom (first) item of this IBList.
#define IBList_BOT(this, Type) *(Type *)IBList_firstItem(this)
IBList_TOP— Dereference top (last) item of this IBList.
#define IBList_TOP(this, Type) *(Type *)IBList_lastItem(this)
IBList_FOREACH— Iterates from first to last IBList item.

Exiting IBList_FOREACH with break or return is allowed.

this
The IBList.
Type
Type of the inlined items.
iter
Type* pointer set to each item.
#define IBList_FOREACH(this, Type, iter) { \
  IBListBlock IBList_FIRSTBLOCK = IBList_firstBlock(this); \
  IBListBlock IBList_PAST = IBList_past(this); \
  int32_t IBList_BLOCKING = IBList_blocking(this); \
  Except_CHECK(sizeof(Type) == IBList_itemSize(this)); \
  while (IBList_FIRSTBLOCK != NULL) { \
    IBListBlock IBList_NEXTBLOCK = IDListItem_NEXT(IBList_FIRSTBLOCK); \
    Type *IBList_BASE = (Type *)IBList_FIRSTBLOCK; \
    Type *IBList_OVERITEM = IBList_NEXTBLOCK != NULL? \
                            IBList_BASE + IBList_BLOCKING: \
                            (Type *)IBList_PAST; \
    Type *IBList_ITERITEM = IBList_BASE; \
    for (; IBList_ITERITEM < IBList_OVERITEM; IBList_ITERITEM++) { \
      Type *(iter) = IBList_ITERITEM;
#define IBList_ENDEACH \
    } \
    if (IBList_ITERITEM < IBList_OVERITEM) break; \
    IBList_FIRSTBLOCK = IBList_NEXTBLOCK; \
  } \
}
IBList_push— Push as last item on the IBList.
Return
The pushed IBListItem.
static inline IBListItem
IBList_push(IBList this)
{
  size_t itemSize = IBList_ITEMSIZE(this);
  int32_t blocking = IBList_BLOCKING(this);
  size_t blockSize = blocking*itemSize;
  char *past = IBList_PAST(this);
  IDList blockList = IBList_BLOCKLIST(this);
  char *lastBlock = IBList_LASTBLOCK(this);
  if (lastBlock == NULL) {
    past = IDList_push(blockList, blockSize);
    *IBList__FIRSTITEM(this) = past;
  } else if (past >= lastBlock + blockSize) {
    past = IDList_push(blockList, blockSize);
  }
  *IBList__PAST(this) = past + itemSize;
  return past;
}

IBList_PUSH - Macro used to IBList_push value types.

#define IBList_PUSH(this, Type, value) \
  (*(Type *)IBList_push(this) = (value))
IBList_put— Put as first item on the IBList.
Return
The put IBListItem.
IBListItem
IBList_put(IBList this);

IBList_PUT - Macro used to IBList_put value types.

#define IBList_PUT(this, Type, value) \
  (*(Type *)IBList_put(this) = (value))
IBList_pop— Pop the last IBList item.
Return
True iff items remain in this IBList.
bool
IBList_pop(IBList this, IBListItemRelease release);

IBList_POP - Macro used to IBList_pop value types.

#define IBList_POP(this, Type, value) \
  ((value) = *(Type *)IBList_lastItem(this), IBList_pop(this))
IBList_drop— Drop the first IBList item.
Return
True iff items remain in this IBList.
bool
IBList_drop(IBList this, IBListItemRelease release);

IBList_DROP - Macro used to IBList_drop value types.

#define IBList_DROP(this, Type, value) \
  ((value) = *(Type *)IBList_firstItem(this), IBList_drop(this))