forked from orren/calico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalico_prop_library.h
101 lines (82 loc) · 1.71 KB
/
calico_prop_library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef _calico_props
#define _calico_props
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int key = 8947;
int multiply_int(int a, int factor) {
return a * factor;
}
/*
int sum ( int arr [], int length ) {
int i = 0, r = 0;
for (; i < length;) r += arr[i++];
return r;
}
*/
int* negate (int* n) {
*n = (*n) * (-1);
return n;
}
int id(int n) {
return n;
}
int double_int(int n) {
return n * 2;
}
int* duplicate(int *a, int length) {
int* res = malloc(sizeof(int) * (length * 2));
int i;
for (i = 0; i < length; i++) {
res[i] = a[i];
}
int j;
for (j = 0; j < length; j++, i++) {
res[i] = a[j];
}
return res;
}
int* multiply_int_array(int *a, int factor, int length) {
int i;
for (i = 0; i < length; i++) a[i] *= factor;
return a;
}
double multiply_double(double a, double factor) {
return a * factor;
}
double* multiply_double_array(double* a, double factor, double length) {
int i;
for (i = 0; i < length; i++) a[i] *= factor;
return a;
}
int* permute_int(int A[], int length) {
srand(time(NULL));
int i;
for (i = 0; i < length; i++) {
int which = rand() % length;
int temp = A[i];
A[i] = A[which];
A[which] = temp;
}
return A;
}
void* permute(void* base, size_t nmemb, size_t size) {
srand(time(NULL));
int i;
void * temp = malloc(size);
for (i = 0; i < nmemb; i++) {
int which = rand() % nmemb;
memcpy(temp, (base + (which * size)), size);
memcpy((base + (which * size)), (base + (i * size)), size);
memcpy((base + (i * size)), temp, size);
}
return base;
}
#endif