• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ConsistentHash.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   @section license License
00004 
00005   Licensed to the Apache Software Foundation (ASF) under one
00006   or more contributor license agreements.  See the NOTICE file
00007   distributed with this work for additional information
00008   regarding copyright ownership.  The ASF licenses this file
00009   to you under the Apache License, Version 2.0 (the
00010   "License"); you may not use this file except in compliance
00011   with the License.  You may obtain a copy of the License at
00012 
00013       http://www.apache.org/licenses/LICENSE-2.0
00014 
00015   Unless required by applicable law or agreed to in writing, software
00016   distributed under the License is distributed on an "AS IS" BASIS,
00017   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018   See the License for the specific language governing permissions and
00019   limitations under the License.
00020  */
00021 
00022 #ifndef __CONSISTENT_HASH_H__
00023 #define __CONSISTENT_HASH_H__
00024 
00025 #include "Hash.h"
00026 #include <stdint.h>
00027 #include <iostream>
00028 #include <map>
00029 
00030 /*
00031   Helper class to be extended to make ring nodes.
00032  */
00033 
00034 struct ATSConsistentHashNode
00035 {
00036   bool available;
00037   char *name;
00038 };
00039 
00040 std::ostream &
00041 operator<< (std::ostream & os, ATSConsistentHashNode & thing);
00042 
00043 typedef std::map<uint64_t, ATSConsistentHashNode *>::iterator ATSConsistentHashIter;
00044 
00045 /*
00046   TSConsistentHash requires a TSHash64 object
00047 
00048   Caller is responsible for freeing ring node memory.
00049  */
00050 
00051 struct ATSConsistentHash
00052 {
00053   ATSConsistentHash(int r = 1024, ATSHash64 *h = NULL);
00054   void insert(ATSConsistentHashNode *node, float weight = 1.0, ATSHash64 *h = NULL);
00055   ATSConsistentHashNode *lookup(const char *url = NULL, ATSConsistentHashIter *i = NULL, bool *w = NULL, ATSHash64 *h = NULL);
00056   ATSConsistentHashNode *lookup_available(const char *url = NULL, ATSConsistentHashIter *i = NULL, bool *w = NULL, ATSHash64 *h = NULL);
00057   ~ATSConsistentHash();
00058 
00059 private:
00060   int replicas;
00061   ATSHash64 *hash;
00062   std::map<uint64_t, ATSConsistentHashNode *> NodeMap;
00063 };
00064 
00065 #endif

Generated by  doxygen 1.7.1