aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-17 18:45:08 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-17 18:45:08 +0100
commit914a279624f7252b5981c988f583d17d119c0918 (patch)
treecc00636602950497230dce563f350952b5446780
parente9991466a43114ded948a397a57f68f23168c809 (diff)
downloadprops.lv2-914a279624f7252b5981c988f583d17d119c0918.tar.xz
fix qsort.
-rw-r--r--props.h34
1 files changed, 19 insertions, 15 deletions
diff --git a/props.h b/props.h
index beb666a..312e98d 100644
--- a/props.h
+++ b/props.h
@@ -234,40 +234,44 @@ _impl_unlock(props_impl_t *impl)
}
static inline void
-_impl_qsort(props_impl_t *a, unsigned n)
+_impl_qsort(props_impl_t *A, int n)
{
if(n < 2)
return;
- const props_impl_t *p = &a[n/2];
+ const props_impl_t *p = A;
- unsigned i, j;
- for(i=0, j=n-1; ; i++, j--)
+ int i = -1;
+ int j = n;
+
+ while(true)
{
- while(a[i].property < p->property)
- i++;
+ do {
+ i += 1;
+ } while(A[i].property < p->property);
- while(p->property < a[j].property)
- j--;
+ do {
+ j -= 1;
+ } while(A[j].property > p->property);
if(i >= j)
break;
- const props_impl_t t = a[i];
- a[i] = a[j];
- a[j] = t;
+ const props_impl_t tmp = A[i];
+ A[i] = A[j];
+ A[j] = tmp;
}
- _impl_qsort(a, i);
- _impl_qsort(&a[i], n - i);
+ _impl_qsort(A, j + 1);
+ _impl_qsort(A + j + 1, n - j - 1);
}
static inline props_impl_t *
-_impl_bsearch(LV2_URID p, props_impl_t *a, unsigned n)
+_impl_bsearch(LV2_URID p, props_impl_t *a, int n)
{
props_impl_t *base = a;
- for(unsigned N = n, half; N > 1; N -= half)
+ for(int N = n, half; N > 1; N -= half)
{
half = N/2;
props_impl_t *dst = &base[half];