1
- /*
2
- * Copyright (c) 2017, Emory University, All rights reserved.
3
- * Juncheng Yang <jason.yang.china@outlook.com>
4
- *
5
- * Modify for libCacheSim based on original version
6
- * also add const modifier for compiler optimizations
7
- *
8
- */
9
-
10
-
11
-
1
+ /*
2
+ * Copyright (c) 2017, Emory University, All rights reserved.
3
+ * Juncheng Yang <jason.yang.china@outlook.com>
4
+ *
5
+ * Modify for libCacheSim based on original version
6
+ * also add const modifier for compiler optimizations
7
+ *
8
+ */
12
9
13
10
/*
14
- * Copyright (c) 2007, Last.fm, All rights reserved.
15
- * Richard Jones <rj@last.fm>
16
- * Christian Muehlhaeuser <muesli@gmail.com>
17
- *
18
- * Redistribution and use in source and binary forms, with or without
19
- * modification, are permitted provided that the following conditions are met:
20
- * * Redistributions of source code must retain the above copyright
21
- * notice, this list of conditions and the following disclaimer.
22
- * * Redistributions in binary form must reproduce the above copyright
23
- * notice, this list of conditions and the following disclaimer in the
24
- * documentation and/or other materials provided with the distribution.
25
- * * Neither the name of the Last.fm Limited nor the
26
- * names of its contributors may be used to endorse or promote products
27
- * derived from this software without specific prior written permission.
28
- *
29
- * THIS SOFTWARE IS PROVIDED BY Last.fm ``AS IS'' AND ANY
30
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
- * DISCLAIMED. IN NO EVENT SHALL Last.fm BE LIABLE FOR ANY
33
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
- */
11
+ * Copyright (c) 2007, Last.fm, All rights reserved.
12
+ * Richard Jones <rj@last.fm>
13
+ * Christian Muehlhaeuser <muesli@gmail.com>
14
+ *
15
+ * Redistribution and use in source and binary forms, with or without
16
+ * modification, are permitted provided that the following conditions are met:
17
+ * * Redistributions of source code must retain the above copyright
18
+ * notice, this list of conditions and the following disclaimer.
19
+ * * Redistributions in binary form must reproduce the above copyright
20
+ * notice, this list of conditions and the following disclaimer in the
21
+ * documentation and/or other materials provided with the distribution.
22
+ * * Neither the name of the Last.fm Limited nor the
23
+ * names of its contributors may be used to endorse or promote products
24
+ * derived from this software without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY Last.fm ``AS IS'' AND ANY
27
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
+ * DISCLAIMED. IN NO EVENT SHALL Last.fm BE LIABLE FOR ANY
30
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ */
40
37
41
38
#ifndef KETAMA_LIBKETAMA_KETAMA_H__
42
39
#define KETAMA_LIBKETAMA_KETAMA_H__
43
40
44
- #include <sys/sem.h> /* semaphore functions and structs. */
41
+ #include <sys/sem.h> /* semaphore functions and structs. */
45
42
46
- #define MC_SHMSIZE 524288 // 512KB should be ample.
43
+ #define MC_SHMSIZE 524288 // 512KB should be ample.
47
44
48
45
#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
49
46
extern "C" {
50
47
#endif
51
48
52
49
#ifndef __APPLE__
53
- union semun
54
- {
55
- int val ; /* used for SETVAL only */
56
- struct semid_ds * buf ; /* for IPC_STAT and IPC_SET */
57
- ushort * array ; /* used for GETALL and SETALL */
50
+ union semun {
51
+ int val ; /* used for SETVAL only */
52
+ struct semid_ds * buf ; /* for IPC_STAT and IPC_SET */
53
+ ushort * array ; /* used for GETALL and SETALL */
58
54
};
59
55
#endif
60
56
@@ -67,64 +63,63 @@ typedef struct {
67
63
68
64
typedef struct {
69
65
char addr [22 ];
70
- unsigned long memory ; // in CDNSimulator, this is used as weight
66
+ unsigned long memory ; // in CDNSimulator, this is used as weight
71
67
} serverinfo ;
72
68
73
69
typedef struct {
74
70
int numpoints ;
75
71
void * modtime ;
76
- void * array ; // array of mcs structs
72
+ void * array ; // array of mcs structs
77
73
} continuum ;
78
74
79
75
typedef continuum * ketama_continuum ;
80
76
81
77
/** build a consistent hashing ring
82
- * given the number of servers and the weight of each server.
83
- * if weight is NULL, then each server has equal weight.
84
- * key_identifier is just a number for identifying shared memory */
78
+ * given the number of servers and the weight of each server.
79
+ * if weight is NULL, then each server has equal weight.
80
+ * key_identifier is just a number for identifying shared memory */
85
81
int ketama_build_hashring (ketama_continuum * const contptr ,
86
82
const unsigned int num_servers ,
87
83
const unsigned long * const weight ,
88
84
const int key_identifier );
89
85
90
- int ketama_get_server_index (
91
- const ketama_continuum cont ,
92
- const char * const key );
86
+ int ketama_get_server_index (const ketama_continuum cont , const char * const key );
93
87
94
- void ketama_get_server_indexes (
95
- const ketama_continuum cont ,
96
- const char * const key ,
97
- unsigned int n , int * indexes );
88
+ void ketama_get_server_indexes (const ketama_continuum cont ,
89
+ const char * const key , unsigned int n ,
90
+ int * indexes );
98
91
99
92
/** \brief Get a continuum struct that contains a reference to the server list.
100
- * \param contptr The value of this pointer will contain the retrieved continuum.
101
- * \param filename The server-definition file which defines our continuum.
102
- * \return 0 on failure, 1 on success. */
93
+ * \param contptr The value of this pointer will contain the retrieved
94
+ * continuum.
95
+ * \param filename The server-definition file which defines our continuum.
96
+ * \return 0 on failure, 1 on success. */
103
97
int ketama_roll (ketama_continuum * contptr , char * filename );
104
98
105
99
/** \brief Frees any allocated memory.
106
- * \param contptr The continuum that you want to be destroy. */
100
+ * \param contptr The continuum that you want to be destroy. */
107
101
void ketama_smoke (ketama_continuum contptr );
108
102
109
103
/** \brief Maps a key onto a server in the continuum.
110
- * \param key The key that you want to map to a specific server.
111
- * \param cont Pointer to the continuum in which we will search.
112
- * \return The mcs struct that the given key maps to. */
104
+ * \param key The key that you want to map to a specific server.
105
+ * \param cont Pointer to the continuum in which we will search.
106
+ * \return The mcs struct that the given key maps to. */
113
107
mcs * ketama_get_server (char * key , ketama_continuum cont );
114
108
115
109
/** \brief Print the server list of a continuum to stdout.
116
- * \param c The continuum to print. */
110
+ * \param c The continuum to print. */
117
111
void ketama_print_continuum (ketama_continuum c );
118
112
119
113
/** \brief Compare two server entries in the circle.
120
- * \param a The first entry.
121
- * \param b The second entry.
122
- * \return -1 if b greater a, +1 if a greater b or 0 if both are equal. */
114
+ * \param a The first entry.
115
+ * \param b The second entry.
116
+ * \return -1 if b greater a, +1 if a greater b or 0 if both are equal. */
123
117
int ketama_compare (mcs * a , mcs * b );
124
118
125
- /** \brief Hashing function, converting a string to an unsigned int by using MD5.
126
- * \param inString The string that you want to hash.
127
- * \return The resulting hash. */
119
+ /** \brief Hashing function, converting a string to an unsigned int by using
120
+ * MD5.
121
+ * \param inString The string that you want to hash.
122
+ * \return The resulting hash. */
128
123
unsigned int ketama_hashi (const char * const inString );
129
124
130
125
/** \brief Hashing function to 16 bytes char array using MD5.
@@ -133,12 +128,11 @@ unsigned int ketama_hashi(const char *const inString);
133
128
void ketama_md5_digest (const char * const inString , unsigned char md5pword [16 ]);
134
129
135
130
/** \brief Error method for error checking.
136
- * \return The latest error that occurred. */
131
+ * \return The latest error that occurred. */
137
132
char * ketama_error ();
138
133
139
134
#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
140
135
}
141
136
#endif
142
137
143
- #endif // KETAMA_LIBKETAMA_KETAMA_H__
144
-
138
+ #endif // KETAMA_LIBKETAMA_KETAMA_H__
0 commit comments