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+ */
129
1310/*
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+ */
4037
4138#ifndef KETAMA_LIBKETAMA_KETAMA_H__
4239#define KETAMA_LIBKETAMA_KETAMA_H__
4340
44- #include <sys/sem.h> /* semaphore functions and structs. */
41+ #include <sys/sem.h> /* semaphore functions and structs. */
4542
46- #define MC_SHMSIZE 524288 // 512KB should be ample.
43+ #define MC_SHMSIZE 524288 // 512KB should be ample.
4744
4845#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
4946extern "C" {
5047#endif
5148
5249#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 */
5854};
5955#endif
6056
@@ -67,64 +63,63 @@ typedef struct {
6763
6864typedef struct {
6965 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
7167} serverinfo ;
7268
7369typedef struct {
7470 int numpoints ;
7571 void * modtime ;
76- void * array ; // array of mcs structs
72+ void * array ; // array of mcs structs
7773} continuum ;
7874
7975typedef continuum * ketama_continuum ;
8076
8177/** 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 */
8581int ketama_build_hashring (ketama_continuum * const contptr ,
8682 const unsigned int num_servers ,
8783 const unsigned long * const weight ,
8884 const int key_identifier );
8985
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 );
9387
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 );
9891
9992/** \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. */
10397int ketama_roll (ketama_continuum * contptr , char * filename );
10498
10599/** \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. */
107101void ketama_smoke (ketama_continuum contptr );
108102
109103/** \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. */
113107mcs * ketama_get_server (char * key , ketama_continuum cont );
114108
115109/** \brief Print the server list of a continuum to stdout.
116- * \param c The continuum to print. */
110+ * \param c The continuum to print. */
117111void ketama_print_continuum (ketama_continuum c );
118112
119113/** \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. */
123117int ketama_compare (mcs * a , mcs * b );
124118
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. */
128123unsigned int ketama_hashi (const char * const inString );
129124
130125/** \brief Hashing function to 16 bytes char array using MD5.
@@ -133,12 +128,11 @@ unsigned int ketama_hashi(const char *const inString);
133128void ketama_md5_digest (const char * const inString , unsigned char md5pword [16 ]);
134129
135130/** \brief Error method for error checking.
136- * \return The latest error that occurred. */
131+ * \return The latest error that occurred. */
137132char * ketama_error ();
138133
139134#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
140135}
141136#endif
142137
143- #endif // KETAMA_LIBKETAMA_KETAMA_H__
144-
138+ #endif // KETAMA_LIBKETAMA_KETAMA_H__
0 commit comments