Changeset: 95f9ff39f21a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=95f9ff39f21a
Modified Files:
        common/utils/mtwist.c
        common/utils/mtwist.h
        gdk/gdk_sample.c
Branch: stratified_sampling
Log Message:

Fix formatting


diffs (truncated from 317 to 300 lines):

diff --git a/common/utils/mtwist.c b/common/utils/mtwist.c
--- a/common/utils/mtwist.c
+++ b/common/utils/mtwist.c
@@ -49,9 +49,9 @@
 #define MTWIST_MATRIX_A 0x9908B0DFUL
 
 #define MTWIST_MIXBITS(u, v) (((u)&MTWIST_UPPER_MASK) | 
((v)&MTWIST_LOWER_MASK))
-#define MTWIST_TWIST(u, v)       \
-    ((MTWIST_MIXBITS(u, v) >> 1) ^ \
-     ((v)&1UL ? MTWIST_MATRIX_A : 0UL))
+#define MTWIST_TWIST(u, v)        \
+       ((MTWIST_MIXBITS(u, v) >> 1) ^ \
+        ((v)&1UL ? MTWIST_MATRIX_A : 0UL))
 
 /**
  * mtwist_new:
@@ -61,16 +61,16 @@
  * Return value: new MT object or NULL on failure
  */
 mtwist* mtwist_new(void) {
-    mtwist* mt;
+       mtwist* mt;
 
-    mt = (mtwist*)calloc(1, sizeof(*mt));
-    if (!mt) return NULL;
+       mt = (mtwist*)calloc(1, sizeof(*mt));
+       if (!mt) return NULL;
 
-    mt->remaining = 0;
-    mt->next = NULL;
-    mt->seeded = 0;
+       mt->remaining = 0;
+       mt->next = NULL;
+       mt->seeded = 0;
 
-    return mt;
+       return mt;
 }
 
 /**
@@ -80,7 +80,7 @@ mtwist* mtwist_new(void) {
  * Destroy a Mersenne Twister object
  */
 void mtwist_free(mtwist* mt) {
-    if (mt) free(mt);
+       if (mt) free(mt);
 }
 
 /**
@@ -91,38 +91,38 @@ void mtwist_free(mtwist* mt) {
  * Initialise a Mersenne Twister with an unsigned 32 bit int seed
  */
 void mtwist_seed(mtwist* mt, unsigned int seed) {
-    int i;
+       int i;
 
-    if (!mt) return;
+       if (!mt) return;
 
-    mt->state[0] = (unsigned int)(seed & MTWIST_FULL_MASK);
-    for (i = 1; i < MTWIST_N; i++) {
-        mt->state[i] =
-            (1812433253UL * (mt->state[i - 1] ^ (mt->state[i - 1] >> 30)) +
-             i);
-        mt->state[i] &= MTWIST_FULL_MASK;
-    }
+       mt->state[0] = (unsigned int)(seed & MTWIST_FULL_MASK);
+       for (i = 1; i < MTWIST_N; i++) {
+               mt->state[i] =
+                       (1812433253UL * (mt->state[i - 1] ^ (mt->state[i - 1] 
>> 30)) +
+                        i);
+               mt->state[i] &= MTWIST_FULL_MASK;
+       }
 
-    mt->remaining = 0;
-    mt->next = NULL;
+       mt->remaining = 0;
+       mt->next = NULL;
 
-    mt->seeded = 1;
+       mt->seeded = 1;
 }
 
 static void mtwist_update_state(mtwist* mt) {
-    int count;
-    unsigned int* p = mt->state;
+       int count;
+       unsigned int* p = mt->state;
 
-    for (count = (MTWIST_N - MTWIST_M + 1); --count; p++)
-        *p = p[MTWIST_M] ^ MTWIST_TWIST(p[0], p[1]);
+       for (count = (MTWIST_N - MTWIST_M + 1); --count; p++)
+               *p = p[MTWIST_M] ^ MTWIST_TWIST(p[0], p[1]);
 
-    for (count = MTWIST_M; --count; p++)
-        *p = p[MTWIST_M - MTWIST_N] ^ MTWIST_TWIST(p[0], p[1]);
+       for (count = MTWIST_M; --count; p++)
+               *p = p[MTWIST_M - MTWIST_N] ^ MTWIST_TWIST(p[0], p[1]);
 
-    *p = p[MTWIST_M - MTWIST_N] ^ MTWIST_TWIST(p[0], mt->state[0]);
+       *p = p[MTWIST_M - MTWIST_N] ^ MTWIST_TWIST(p[0], mt->state[0]);
 
-    mt->remaining = MTWIST_N;
-    mt->next = mt->state;
+       mt->remaining = MTWIST_N;
+       mt->next = mt->state;
 }
 
 /**
@@ -134,26 +134,26 @@ static void mtwist_update_state(mtwist* 
  * Return value: unsigned int with 32 valid bits
  */
 inline unsigned int mtwist_u32rand(mtwist* mt) {
-    unsigned int r;
+       unsigned int r;
 
-    if (!mt) return 0UL;
+       if (!mt) return 0UL;
 
-    if (!mt->seeded) mtwist_seed(mt, 0);
+       if (!mt->seeded) mtwist_seed(mt, 0);
 
-    if (!mt->remaining) mtwist_update_state(mt);
+       if (!mt->remaining) mtwist_update_state(mt);
 
-    r = *mt->next++;
-    mt->remaining--;
+       r = *mt->next++;
+       mt->remaining--;
 
-    /* Tempering */
-    r ^= (r >> 11);
-    r ^= (r << 7) & 0x9D2C5680UL;
-    r ^= (r << 15) & 0xEFC60000UL;
-    r ^= (r >> 18);
+       /* Tempering */
+       r ^= (r >> 11);
+       r ^= (r << 7) & 0x9D2C5680UL;
+       r ^= (r << 15) & 0xEFC60000UL;
+       r ^= (r >> 18);
 
-    r &= MTWIST_FULL_MASK;
+       r &= MTWIST_FULL_MASK;
 
-    return r;
+       return r;
 }
 
 /**
@@ -165,16 +165,16 @@ inline unsigned int mtwist_u32rand(mtwis
  * Return value: random double in the range 0.0 inclusive to 1.0 exclusive;
  *[0.0, 1.0) */
 inline double mtwist_drand(mtwist* mt) {
-    unsigned int r;
-    double d;
+       unsigned int r;
+       double d;
 
-    if (!mt) return 0.0;
+       if (!mt) return 0.0;
 
-    r = mtwist_u32rand(mt);
+       r = mtwist_u32rand(mt);
 
-    d = r / 4294967296.0; /* 2^32 */
+       d = r / 4294967296.0; /* 2^32 */
 
-    return d;
+       return d;
 }
 
 
@@ -189,29 +189,29 @@ inline double mtwist_drand(mtwist* mt) {
  * [a,b] 
  */
 inline int mtwist_uniform_int(mtwist* mt, int a, int b) {
-    unsigned int range, scale, max_x, x;
-    if(b < a) {//invalid range!
-        return 0;
-    }
-    range = b-a+1;
-    scale = 4294967295UL/range;
-        //4294967295UL=2^32-1=RAND_MAX for this Mersenne Twister
-    max_x = range*scale;
+       unsigned int range, scale, max_x, x;
+       if(b < a) {//invalid range!
+               return 0;
+       }
+       range = b-a+1;
+       scale = 4294967295UL/range;
+               //4294967295UL=2^32-1=RAND_MAX for this Mersenne Twister
+       max_x = range*scale;
 
-    //x will be uniform in [0, max_x[
-    //Since past%range=0, x%range will be uniform in [0,range[
-    do {
-        x = mtwist_u32rand(mt);
-    } while(x >= max_x);
+       //x will be uniform in [0, max_x[
+       //Since past%range=0, x%range will be uniform in [0,range[
+       do {
+               x = mtwist_u32rand(mt);
+       } while(x >= max_x);
 
-    return a+(x/scale);
-    //x is uniform in [0,max_x[ = [0,range*scale[
-    //hence x/scale is uniform in [0,range[=[0,b-a+1[
-    //thus a+(x/scale) is uniform in [a,b]
-    
-    //alternative: return a+(x%range); 
-    //x is uniform in [0,max_x[ = [0,range*scale[
-    //hence (x%range) is uniform in [0,range[=[0,b-a+1[
-    //thus a+(x%range) is uniform in [a,b]
+       return a+(x/scale);
+       //x is uniform in [0,max_x[ = [0,range*scale[
+       //hence x/scale is uniform in [0,range[=[0,b-a+1[
+       //thus a+(x/scale) is uniform in [a,b]
+       
+       //alternative: return a+(x%range); 
+       //x is uniform in [0,max_x[ = [0,range*scale[
+       //hence (x%range) is uniform in [0,range[=[0,b-a+1[
+       //thus a+(x%range) is uniform in [a,b]
 }
 
diff --git a/common/utils/mtwist.h b/common/utils/mtwist.h
--- a/common/utils/mtwist.h
+++ b/common/utils/mtwist.h
@@ -36,17 +36,17 @@
 
 /* Mersenne Twister library state */
 struct mtwist_s {
-    /* MT buffer holding N 32 bit unsigned integers */
-    unsigned int state[MTWIST_N];
+       /* MT buffer holding N 32 bit unsigned integers */
+       unsigned int state[MTWIST_N];
 
-    /* Pointer into above - next int to use */
-    unsigned int* next;
+       /* Pointer into above - next int to use */
+       unsigned int* next;
 
-    /* Number of remaining integers in state before an update is needed */
-    unsigned int remaining;
+       /* Number of remaining integers in state before an update is needed */
+       unsigned int remaining;
 
-    /* 1 if a seed was given */
-    unsigned int seeded : 1;
+       /* 1 if a seed was given */
+       unsigned int seeded : 1;
 };
 
 /* Mersenne Twister state */
diff --git a/gdk/gdk_sample.c b/gdk/gdk_sample.c
--- a/gdk/gdk_sample.c
+++ b/gdk/gdk_sample.c
@@ -81,16 +81,16 @@ OIDTreeToBATAntiset(struct oidtreenode *
        oid noid;
 
        if (node->left != NULL)
-               OIDTreeToBATAntiset(node->left, bat, start, node->o);
+                       OIDTreeToBATAntiset(node->left, bat, start, node->o);
        else
                for (noid = start; noid < node->o; noid++)
                        ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
 
-        if (node->right != NULL)
+               if (node->right != NULL)
                OIDTreeToBATAntiset(node->right, bat, node->o + 1, stop);
        else
                for (noid = node->o+1; noid < stop; noid++)
-                        ((oid *) bat->T->heap.base)[bat->batFirst + 
bat->batCount++] = noid;
+                                               ((oid *) 
bat->T->heap.base)[bat->batFirst + bat->batCount++] = noid;
 }
 
 /* BATsample implements sampling for void headed BATs */
@@ -101,8 +101,8 @@ BATsample(BAT *b, BUN n)
        BUN cnt, slen;
        BUN rescnt;
        struct oidtreenode *tree = NULL;
-    mtwist *mt_rng;
-    unsigned int range;
+       mtwist *mt_rng;
+       unsigned int range;
 
        BATcheck(b, "BATsample", NULL);
        assert(BAThdense(b));
@@ -149,20 +149,20 @@ BATsample(BAT *b, BUN n)
                        return NULL;
                }
                /* while we do not have enough sample OIDs yet */
-        
-        /* create and seed Mersenne Twister */
-        mt_rng = mtwist_new();
+               
+               /* create and seed Mersenne Twister */
+               mt_rng = mtwist_new();
 
-        mtwist_seed(mt_rng, rand());
-        
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to