return length;
}
+// ------------------------------- median -------------------------------------
+
+float medianf(float*a, int n)
+{
+ int i,j,l,m;
+ float x;
+ int k=n&1?n/2:n/2-1;
+ l=0;
+ m=n-1;
+ while(l<m) {
+ x=a[k];
+ i=l;j=m;
+ do {
+ while(a[i]<x) i++;
+ while(x<a[j]) j--;
+ if(i<=j) {
+ //swap
+ float t = a[i];
+ a[i] = a[j];
+ a[j] = t;
+ i++;
+ j--;
+ }
+ } while(i<=j);
+ if(j<k) l=i;
+ if(k<i) m=j;
+ }
+ return a[k];
+}
+
// ------------------------------- ringbuffer_t -------------------------------
typedef struct _ringbuffer_internal_t
{
if(!*t) {
(*t) = rfx_calloc(sizeof(trielayer_t));
- (*t)->rest = (unsigned char*)strdup(id);
+ (*t)->rest = (unsigned char*)strdup((char*)id);
(*t)->data = data;
return 0;
}
char overwrite = 0;
if((*t)->rest)
overwrite = 1;
- (*t)->rest = strdup("");
+ (*t)->rest = (unsigned char*)strdup("");
(*t)->data = data;
return overwrite;
}
static char _trie_remove(trielayer_t*t, unsigned const char*id)
{
while(t) {
- if(t->rest && !strcmp(t->rest, id)) {
+ if(t->rest && !strcmp((char*)t->rest, (char*)id)) {
free(t->rest);
t->rest = 0;
return 1;
{
trielayer_t*t = trie->start;
while(t) {
- if(t->rest && !strcmp(t->rest, id))
+ if(t->rest && !strcmp((char*)t->rest, (char*)id))
return 1;
if(!*id)
return 0;
{
trielayer_t*t = trie->start;
while(t) {
- if(t->rest && !strcmp(t->rest, id))
+ if(t->rest && !strcmp((char*)t->rest, (char*)id))
return t->data;
if(!*id)
return 0;
unsigned int crc32_add_byte(unsigned int checksum, unsigned char b)
{
- if(!crc32)
- crc32_init();
+ crc32_init();
return checksum>>8 ^ crc32[(b^checksum)&0xff];
}
unsigned int crc32_add_string(unsigned int checksum, const char*s)
{
- if(!crc32)
- crc32_init();
+ crc32_init();
if(!s)
return checksum;
while(*s) {
{
int t;
unsigned int checksum = 0;
- if(!crc32)
- crc32_init();
+ crc32_init();
for(t=0;t<str->len;t++) {
checksum = checksum>>8 ^ crc32[(str->str[t]^checksum)&0xff];
}
{
unsigned int checksum = 0;
const char*p = str;
- if(!crc32)
- crc32_init();
+ crc32_init();
while(*p) {
checksum = checksum>>8 ^ crc32[(*p^checksum)&0xff];
p++;
return 0;
}
+char dict_del2(dict_t*h, const void*key, void*data)
+{
+ if(!h->num)
+ return 0;
+ unsigned int hash = h->key_type->hash(key) % h->hashsize;
+ dictentry_t*head = h->slots[hash];
+ dictentry_t*e = head, *prev=0;
+ while(e) {
+ if(h->key_type->equals(e->key, key) && e->data == data) {
+ dictentry_t*next = e->next;
+ h->key_type->free(e->key);
+ memset(e, 0, sizeof(dictentry_t));
+ rfx_free(e);
+ if(e == head) {
+ h->slots[hash] = next;
+ } else {
+ assert(prev);
+ prev->next = next;
+ }
+ h->num--;
+ return 1;
+ }
+ prev = e;
+ e = e->next;
+ }
+ return 0;
+}
+
dictentry_t* dict_get_slot(dict_t*h, const void*key)
{
if(!h->num)
}
void*array_getkey(array_t*array, int nr) {
if(nr > array->num || nr<0) {
- printf("error: reference to element %d in array[%d]\n", nr, array->num);
+ fprintf(stderr, "error: reference to element %d in array[%d]\n", nr, array->num);
return 0;
}
return array->d[nr].name;
}
void*array_getvalue(array_t*array, int nr) {
if(nr > array->num || nr<0) {
- printf("error: reference to element %d in array[%d]\n", nr, array->num);
+ fprintf(stderr, "error: reference to element %d in array[%d]\n", nr, array->num);
return 0;
}
return array->d[nr].data;