static void * _ba_iterator_last(binary_array_iterator *it) { binary_array_table* t = _ba_it2cont(it); if(NULL == t) { netsnmp_assert(NULL != t); return NULL; } return _ba_iterator_position(it, t->count - 1 ); }
static int _ba_iterator_remove(binary_array_iterator *it) { binary_array_table* t = _ba_it2cont(it); if(NULL == t) { netsnmp_assert(NULL != t); return -1; } /* * since this iterator was used for the remove, keep it in sync with * the container. Also, back up one so that next will be the position * that was just removed. */ ++it->base.sync; return netsnmp_binary_array_remove_at(it->base.container, it->pos--, NULL); }
static int _ba_iterator_reset(binary_array_iterator *it) { binary_array_table* t = _ba_it2cont(it); if(NULL == t) { netsnmp_assert(NULL != t); return -1; } /* * save sync count, to make sure container doesn't change while * iterator is in use. */ it->base.sync = it->base.container->sync; it->pos = 0; return 0; }
NETSNMP_STATIC_INLINE void * _ba_iterator_position(binary_array_iterator *it, size_t pos) { binary_array_table *t = _ba_it2cont(it); if (NULL == t) return t; /* msg already logged */ if(it->base.container->sync != it->base.sync) { DEBUGMSGTL(("container:iterator", "out of sync\n")); return NULL; } if(0 == t->count) { DEBUGMSGTL(("container:iterator", "empty\n")); return NULL; } else if(pos >= t->count) { DEBUGMSGTL(("container:iterator", "end of container\n")); return NULL; } return t->data[ pos ]; }