git.asbjorn.biz
/
swftools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed format warnings
[swftools.git]
/
lib
/
q.c
diff --git
a/lib/q.c
b/lib/q.c
index
fc9f868
..
a2d7a63
100644
(file)
--- a/
lib/q.c
+++ b/
lib/q.c
@@
-113,6
+113,36
@@
int mem_get(mem_t*m, void*data, int length)
return length;
}
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
// ------------------------------- ringbuffer_t -------------------------------
typedef struct _ringbuffer_internal_t
@@
-344,7
+374,7
@@
static char _trie_put(trielayer_t**t, unsigned const char*id, void*data)
{
if(!*t) {
(*t) = rfx_calloc(sizeof(trielayer_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;
}
(*t)->data = data;
return 0;
}
@@
-359,7
+389,7
@@
static char _trie_put(trielayer_t**t, unsigned const char*id, void*data)
char overwrite = 0;
if((*t)->rest)
overwrite = 1;
char overwrite = 0;
if((*t)->rest)
overwrite = 1;
- (*t)->rest = strdup("");
+ (*t)->rest = (unsigned char*)strdup("");
(*t)->data = data;
return overwrite;
}
(*t)->data = data;
return overwrite;
}
@@
-367,7
+397,7
@@
static char _trie_put(trielayer_t**t, unsigned const char*id, void*data)
static char _trie_remove(trielayer_t*t, unsigned const char*id)
{
while(t) {
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;
free(t->rest);
t->rest = 0;
return 1;
@@
-413,7
+443,7
@@
int trie_contains(trie_t*trie, unsigned const char*id)
{
trielayer_t*t = trie->start;
while(t) {
{
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;
return 1;
if(!*id)
return 0;
@@
-425,7
+455,7
@@
void* trie_lookup(trie_t*trie, unsigned const char*id)
{
trielayer_t*t = trie->start;
while(t) {
{
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;
return t->data;
if(!*id)
return 0;
@@
-478,7
+508,7
@@
void _trie_dump(trielayer_t*t, char*buffer, int pos)
}
if(t->rest) {
buffer[pos]=0;
}
if(t->rest) {
buffer[pos]=0;
- printf("%s%s %08x\n", buffer, t->rest, t->data);
+ printf("%s%s %08x\n", buffer, t->rest, (int)t->data);
}
}
}
}
@@
-1053,9
+1083,9
@@
void dict_dump(dict_t*h, FILE*fi, const char*prefix)
dictentry_t*e = h->slots[t];
while(e) {
if(h->key_type!=&charptr_type) {
dictentry_t*e = h->slots[t];
while(e) {
if(h->key_type!=&charptr_type) {
- fprintf(fi, "%s%08x=%08x\n", prefix, e->key, e->data);
+ fprintf(fi, "%s%08x=%08x\n", prefix, (int)e->key, (int)e->data);
} else {
} else {
- fprintf(fi, "%s%s=%08x\n", prefix, e->key, e->data);
+ fprintf(fi, "%s%s=%08x\n", prefix, (char*)e->key, (int)e->data);
}
e = e->next;
}
}
e = e->next;
}
@@
-1307,7
+1337,7
@@
static void freestring(void*data)
static void dumpmapentry(void*data, const void*key, void*value)
{
FILE*fi = (FILE*)data;
static void dumpmapentry(void*data, const void*key, void*value)
{
FILE*fi = (FILE*)data;
- fprintf(fi, "%s=%s\n", key, (char*)value);
+ fprintf(fi, "%s=%s\n", (char*)key, (char*)value);
}
void map_dump(map_t*map, FILE*fi, const char*prefix)
{
}
void map_dump(map_t*map, FILE*fi, const char*prefix)
{
@@
-1343,14
+1373,14
@@
array_t* array_new2(type_t*type) {
}
void*array_getkey(array_t*array, int nr) {
if(nr > array->num || nr<0) {
}
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) {
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;
return 0;
}
return array->d[nr].data;