#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "log.h"
#include "util.h"
Data Structures | |
struct | sortwithindex_t |
Functions | |
int | CheckIfFileExists (char *pcFilename) |
Copy of squid's FileExists(). Copied here to make squid independent. | |
void * | CkMalloc (size_t bytes, const char *function, const int line) |
Allocates memory (malloc). | |
void * | CkCalloc (size_t count, size_t size, const char *function, const int line) |
Allocates memory (calloc). Memory will be set to zero. | |
void * | CkRealloc (void *ptr, size_t bytes, const char *function, const int line) |
Reallocates memory. | |
void * | CkFree (void *ptr, const char *function, const int line) |
Frees memory. | |
char * | CkStrdup (const char *src) |
safe version of strdup | |
void | PermutationArray (int **perm, const int len) |
Creates an int array of size len with len-1 random but unique integers with values 0--len-1. This is "a modified version of Fisher-Yates known as Durstenfeld-Fisher-Yates or Knuth-Fisher-Yates". See http://stackoverflow.com/questions/196017/unique-random-numbers-in-o1. | |
void | RandomUniqueIntArray (int *array, const int array_len, const int max_value) |
Creates an array filled with random, but unique ints of given range. Implementation of the Floyd algorithm. See http://stackoverflow.com/questions/1608181/unique-random-numbers-in-an-integer-array-in-the-c-programming-language Assuming M is the length of the desired array and N is the numeric range: "This approach has the complexity of about O(M) (depends on the search structure used), so it is better suitable when M << N. This approach keeps track of already generated random numbers, so it requires extra memory. However, the beauty of it is that it does not make any of those horrendous "trial and error" iterations, trying to find an unused random number. This algorithm is guaranteed to generate one unique random number after each single call to the random number generator.". | |
int | IntCmp (const void *a, const void *b) |
int comparison function for qsort | |
int | SortAndTrackIndexCmpAsc (const void *a, const void *b) |
Compare two sortwithindex_t pointers and return the difference between the int value of the 1st sortwithindex_t and the 2nd. Used for ascending sort order in QSortWithIndexes()/. | |
int | SortAndTrackIndexCmpDesc (const void *a, const void *b) |
Compare two sortwithindex_t pointers and return the difference between the int value of the 2nd sortwithindex_t and the 1st. Used for descending sort order in QSortWithIndexes(). | |
void | QSortAndTrackIndex (int *piSortedIndices, int *piArrayToSort, const int iArrayLen, const char cOrder, const bool bOverwriteArrayToSort) |
Sort a given int array in ascending or descending order, while keeping track of the element order. | |
bool | FileIsWritable (char *pcFileName) |
Test if file is writable. File may or may not exist. |
int CheckIfFileExists | ( | char * | pcFilename | ) |
Copy of squid's FileExists(). Copied here to make squid independent.
void* CkCalloc | ( | size_t | count, | |
size_t | size, | |||
const char * | function, | |||
const int | line | |||
) |
Allocates memory (calloc). Memory will be set to zero.
[in] | count | Allocate space for count objects |
[in] | size | Objects are of this size |
[in] | function | calling function name |
[in] | line | calling function line |
void* CkFree | ( | void * | ptr, | |
const char * | function, | |||
const int | line | |||
) |
Frees memory.
[in] | ptr | Pointer to memory to be freed |
[in] | function | calling function name |
[in] | line | calling function line |
void* CkMalloc | ( | size_t | bytes, | |
const char * | function, | |||
const int | line | |||
) |
Allocates memory (malloc).
[in] | bytes | bytes to allocated |
[in] | function | calling function name |
[in] | line | calling function line |
void* CkRealloc | ( | void * | ptr, | |
size_t | bytes, | |||
const char * | function, | |||
const int | line | |||
) |
Reallocates memory.
[in] | ptr | Pointer to memory to be reallocated |
[in] | bytes | bytes to allocated |
[in] | function | calling function name |
[in] | line | calling function line |
char* CkStrdup | ( | const char * | src | ) |
safe version of strdup
[in] | src | String to copy from |
bool FileIsWritable | ( | char * | pcFileName | ) |
Test if file is writable. File may or may not exist.
[in] | pcFileName | Filename to check |
int IntCmp | ( | const void * | a, | |
const void * | b | |||
) |
int comparison function for qsort
void PermutationArray | ( | int ** | perm, | |
const int | len | |||
) |
Creates an int array of size len with len-1 random but unique integers with values 0--len-1. This is "a modified version of Fisher-Yates known as Durstenfeld-Fisher-Yates or Knuth-Fisher-Yates". See http://stackoverflow.com/questions/196017/unique-random-numbers-in-o1.
[in] | perm | The permutation array. Has to be preallocated |
[out] | len | Length of the permutation array |
void QSortAndTrackIndex | ( | int * | piSortedIndices, | |
int * | piArrayToSort, | |||
const int | iArrayLen, | |||
const char | cOrder, | |||
const bool | bOverwriteArrayToSort | |||
) |
Sort a given int array in ascending or descending order, while keeping track of the element order.
[out] | piSortedIndices | Will contain the indices of the sorted elements. Has to be preallocated. |
[out] | piArrayToSort | Array with values to sort. Will only be overwritten if bOverwriteArrayToSort it true. |
[in] | iArrayLen | Number of elements in piArrayToSort. |
[in] | cOrder | Sort order. 'a' for ascending, 'd' for descending. |
[in] | bOverwriteArrayToSort | If false do not overwrite the array to sort. |
< aux
void RandomUniqueIntArray | ( | int * | array, | |
const int | array_len, | |||
const int | max_value | |||
) |
Creates an array filled with random, but unique ints of given range. Implementation of the Floyd algorithm. See http://stackoverflow.com/questions/1608181/unique-random-numbers-in-an-integer-array-in-the-c-programming-language Assuming M is the length of the desired array and N is the numeric range: "This approach has the complexity of about O(M) (depends on the search structure used), so it is better suitable when M << N. This approach keeps track of already generated random numbers, so it requires extra memory. However, the beauty of it is that it does not make any of those horrendous "trial and error" iterations, trying to find an unused random number. This algorithm is guaranteed to generate one unique random number after each single call to the random number generator.".
[in] | array | Preallocated int array whose values will be set |
[in] | array_len | Size of array |
[in] | max_value |
int SortAndTrackIndexCmpAsc | ( | const void * | a, | |
const void * | b | |||
) |
Compare two sortwithindex_t pointers and return the difference between the int value of the 1st sortwithindex_t and the 2nd. Used for ascending sort order in QSortWithIndexes()/.
int SortAndTrackIndexCmpDesc | ( | const void * | a, | |
const void * | b | |||
) |
Compare two sortwithindex_t pointers and return the difference between the int value of the 2nd sortwithindex_t and the 1st. Used for descending sort order in QSortWithIndexes().