PostGIS  2.1.10dev-r@@SVN_REVISION@@
static struct quantile_llist_element* quantile_llist_insert ( struct quantile_llist_element element,
double  value,
uint32_t *  idx 
)
static

Definition at line 3943 of file rt_api.c.

References quantile_llist_element::count, quantile_llist_element::next, quantile_llist_element::prev, RASTER_DEBUGF, rtalloc(), genraster::value, and quantile_llist_element::value.

Referenced by rt_band_get_quantiles_stream().

3947  {
3948  struct quantile_llist_element *qle = NULL;
3949 
3950  if (NULL == element) {
3951  qle = rtalloc(sizeof(struct quantile_llist_element));
3952  RASTER_DEBUGF(4, "qle @ %p is only element in list", qle);
3953  if (NULL == qle) return NULL;
3954 
3955  qle->value = value;
3956  qle->count = 1;
3957 
3958  qle->prev = NULL;
3959  qle->next = NULL;
3960 
3961  if (NULL != idx) *idx = 0;
3962  return qle;
3963  }
3964  else if (value > element->value) {
3965  if (NULL != idx) *idx += 1;
3966  if (NULL != element->next)
3967  return quantile_llist_insert(element->next, value, idx);
3968  /* insert as last element in list */
3969  else {
3970  qle = rtalloc(sizeof(struct quantile_llist_element));
3971  RASTER_DEBUGF(4, "insert qle @ %p as last element", qle);
3972  if (NULL == qle) return NULL;
3973 
3974  qle->value = value;
3975  qle->count = 1;
3976 
3977  qle->prev = element;
3978  qle->next = NULL;
3979  element->next = qle;
3980 
3981  return qle;
3982  }
3983  }
3984  /* insert before current element */
3985  else {
3986  qle = rtalloc(sizeof(struct quantile_llist_element));
3987  RASTER_DEBUGF(4, "insert qle @ %p before current element", qle);
3988  if (NULL == qle) return NULL;
3989 
3990  qle->value = value;
3991  qle->count = 1;
3992 
3993  if (NULL != element->prev) element->prev->next = qle;
3994  qle->next = element;
3995  qle->prev = element->prev;
3996  element->prev = qle;
3997 
3998  return qle;
3999  }
4000 }
struct quantile_llist_element * prev
Definition: rt_api.h:2330
struct quantile_llist_element * next
Definition: rt_api.h:2331
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
static struct quantile_llist_element * quantile_llist_insert(struct quantile_llist_element *element, double value, uint32_t *idx)
Definition: rt_api.c:3943

Here is the call graph for this function:

Here is the caller graph for this function: