]> wimlib.net Git - wimlib/blobdiff - include/wimlib/util.h
Improve random number generation
[wimlib] / include / wimlib / util.h
index 7f34cbf39721f0a6e411595f568474bf5db5f6c9..3dc59f454faae2099979af514a7a4994b052a345 100644 (file)
 /* Get the number of elements of an array type.  */
 #define ARRAY_LEN(array)       (sizeof(array) / sizeof((array)[0]))
 
+/* Round 'v' up to the next 'alignment'-byte aligned boundary.  'alignment' must
+ * be a power of 2.  */
+#define ALIGN(v, alignment)    (((v) + ((alignment) - 1)) & ~((alignment) - 1))
+
 /* Maximum number of bytes that can be allocated on the stack.
  *
  * Note: this isn't a hard bound on the stack space used, since this is just for
@@ -84,11 +88,15 @@ extern void *
 mempcpy(void *dst, const void *src, size_t n);
 #endif
 
+/**************************
+ * Random number generation
+ **************************/
+
 extern void
-randomize_byte_array(u8 *p, size_t n);
+get_random_bytes(void *p, size_t n);
 
 extern void
-randomize_char_array_with_alnum(tchar *p, size_t n);
+get_random_alnum_chars(tchar *p, size_t n);
 
 /************************
  * Hashing and comparison
@@ -107,6 +115,16 @@ hash_u64(u64 n)
        return n * 0x9e37fffffffc0001ULL;
 }
 
+static inline int
+cmp_u32(u32 n1, u32 n2)
+{
+       if (n1 < n2)
+               return -1;
+       if (n1 > n2)
+               return 1;
+       return 0;
+}
+
 static inline int
 cmp_u64(u64 n1, u64 n2)
 {