PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ quantile_llist_insert()

static struct quantile_llist_element * quantile_llist_insert ( struct quantile_llist_element element,
double  value,
uint32_t *  idx 
)
static

Definition at line 797 of file rt_statistics.c.

801 {
802 struct quantile_llist_element *qle = NULL;
803
804 if (NULL == element) {
805 qle = rtalloc(sizeof(struct quantile_llist_element));
806 RASTER_DEBUGF(4, "qle @ %p is only element in list", qle);
807 if (NULL == qle) return NULL;
808
809 qle->value = value;
810 qle->count = 1;
811
812 qle->prev = NULL;
813 qle->next = NULL;
814
815 if (NULL != idx) *idx = 0;
816 return qle;
817 }
818 else if (value > element->value) {
819 if (NULL != idx) *idx += 1;
820 if (NULL != element->next)
821 return quantile_llist_insert(element->next, value, idx);
822 /* insert as last element in list */
823 else {
824 qle = rtalloc(sizeof(struct quantile_llist_element));
825 RASTER_DEBUGF(4, "insert qle @ %p as last element", qle);
826 if (NULL == qle) return NULL;
827
828 qle->value = value;
829 qle->count = 1;
830
831 qle->prev = element;
832 qle->next = NULL;
833 element->next = qle;
834
835 return qle;
836 }
837 }
838 /* insert before current element */
839 else {
840 qle = rtalloc(sizeof(struct quantile_llist_element));
841 RASTER_DEBUGF(4, "insert qle @ %p before current element", qle);
842 if (NULL == qle) return NULL;
843
844 qle->value = value;
845 qle->count = 1;
846
847 if (NULL != element->prev) element->prev->next = qle;
848 qle->next = element;
849 qle->prev = element->prev;
850 element->prev = qle;
851
852 return qle;
853 }
854}
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:308
static struct quantile_llist_element * quantile_llist_insert(struct quantile_llist_element *element, double value, uint32_t *idx)
struct quantile_llist_element * prev
Definition librtcore.h:2615
struct quantile_llist_element * next
Definition librtcore.h:2616

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

Referenced by quantile_llist_insert(), and rt_band_get_quantiles_stream().

Here is the call graph for this function:
Here is the caller graph for this function: