Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE)
@param  {string} bucketingKey String value for bucketing
@return {string} the generated bucket value
@throws If bucketing value is not a valid string
343861
function(bucketingKey) {
    try {
      // NOTE: the mmh library already does cast the hash value as an unsigned 32bit int
      // https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L115
      var hashValue = murmurhash.v3(bucketingKey, HASH_SEED);
      var ratio = hashValue / MAX_HASH_VALUE;
      return parseInt(ratio * MAX_TRAFFIC_VALUE, 10);
    } catch (ex) {
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
    }
  }
932579
private V get(K key, int hash) {
    if (hash == this.hash && key.equals(this.key)) {
      return this.value;
    }
    int bucket = bucket(hash);
    int bucketMask = 1 << bucket;
    return (mask & bucketMask) != 0 ? children[index(bucketMask)].get(key, shift(hash)) : null;
  }
573411
function(keys){

  console.log('\nInitializing keys in Redis...\n')

  keys.forEach(function(el,i){

    client.get(el.key, function(e,d){

      if(e) {
        console.log("Error trying to get %s ", el.key)
        return console.error(e)
      }

      // checking for falsey values only is a bad idea
      if(typeof d === 'undefined'){

        console.log("Not OK trying to get %s ", el.key)

        client.set(el.key, el.initialValue, function(e,d){
          if(e) {
            console.log("Error trying to set %s ", el.key)
            return console.error(e)
          }
          if(d !== 'OK') {
            console.log("Not OK trying to set %s ", el.key)
            return console.warn(el.key + " was not set.")
          }
          if(d === 'OK') {
            console.log("OK setting %s ", el.key)
            client.get(el.key, function(e,d){
             console.log(d) 
            })
          }

        }) // end set.
      }

      console.log("The value for key %s is %s", el.key.yellow, d.green)

    }) // end get

  })
}
1054033
function(bucket, key, cb){
		contract(arguments)
			.params('string', 'string|number', 'function')
			.end()
		;
		
		var table = '';
		if (bucket.indexOf('allows') != -1) {
			table = this.prefix + this.buckets.permissions;
			this.db
				.select('key', 'value')
				.from(table)
				.where({'key': bucket})
				.then(function(result) {
					if (result.length) {
						cb(undefined, (result[0].value[key] ? result[0].value[key] : []));
					} else {
						cb(undefined, []);
					}
				})
			;
		} else {
			table = this.prefix + bucket;
			this.db
				.select('key', 'value')
				.from(table)
				.where({'key': key})
				.then(function(result) {
					cb(undefined, (result.length ? result[0].value : []));
				})
			;
		}
	}
1340740
private final int getRoundKey(final int key, final boolean upORdown, final boolean acceptEqual) {
		if (isEmpty())
			return NULL_VALUE;
		int slot = findSlotByKey(key);
		if (upORdown) {
			// ceiling / higher
			slot = ((slot < 0) ? (-slot) - 1 : (acceptEqual ? slot : slot + 1));
			if (slot >= allocated) {
				return NULL_VALUE;
			}
		} else {
			// floor / lower
			slot = ((slot < 0) ? (-slot) - 2 : (acceptEqual ? slot : slot - 1));
			if (slot < 0) {
				return NULL_VALUE;
			}
		}
		return keys[slot];
	}
786344
protected static String bucketId(ApiRequest request, RateLimitingConfig config) {
        StringBuilder builder = new StringBuilder();
        if (request.getContract() == null) {
            builder.append("PUBLIC||"); //$NON-NLS-1$
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiOrgId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(request.getApiVersion());
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String header = config.getUserHeader();
                if (!request.getHeaders().containsKey(header)) {
                    return NO_USER_AVAILABLE;
                }
                String user = request.getHeaders().get(header);
                builder.append("||"); //$NON-NLS-1$
                builder.append(user);
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getRemoteAddr());
            } else if (config.getGranularity() == RateLimitingGranularity.Api) {
            } else {
                return NO_CLIENT_AVAILABLE;
            }
        } else {
            builder.append(request.getApiKey());
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String header = config.getUserHeader();
                String user = request.getHeaders().get(header);
                if (user == null) {
                    return NO_USER_AVAILABLE;
                } else {
                    builder.append("||USER||"); //$NON-NLS-1$
                    builder.append(request.getContract().getClient().getOrganizationId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(request.getContract().getClient().getClientId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(user);
                }
            } else if (config.getGranularity() == RateLimitingGranularity.Client) {
                builder.append(request.getApiKey());
                builder.append("||APP||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getClientId());
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append(request.getApiKey());
                builder.append("||IP||"); //$NON-NLS-1$
                builder.append(request.getContract().getClient().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getRemoteAddr());
            } else {
                builder.append(request.getApiKey());
                builder.append("||SERVICE||"); //$NON-NLS-1$
                builder.append(request.getContract().getApi().getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(request.getContract().getApi().getApiId());
            }
        }
        return builder.toString();
    }
282903
function bitcount(key, start, end /* req */) {
  var req = typeof arguments[arguments.length - 1] === 'object'
    ? arguments[arguments.length - 1] : null
    , buf = this.getValueBuffer(key, req, true)
    , c = 0
    , count = 0
    , bytecount = 16;

  // no key or empty string
  if(buf === undefined || buf.length === 0) return 0;
  // got start/end range
  if(arguments.length >= 3) {
    if(start < 0) start = buf.length + start;
    if(end < 0) end = buf.length + end;
    if(start < 0) start = 0;
    if(end < 0) end = 0;
    if(end > buf.length) end = buf.length;
  }else{
    start = 0;
    end = buf.length;
  }

  if(start > end) return 0;

  // get the range we are inspecting
  buf = buf.slice(start, end + 1);

  function addBitCount(buf) {
    for(var i = 0;i < buf.length;i++) {
      if(buf[i] & 0x80) count++;
      if(buf[i] & 0x40) count++;
      if(buf[i] & 0x20) count++;
      if(buf[i] & 0x10) count++;
      if(buf[i] & 0x08) count++;
      if(buf[i] & 0x04) count++;
      if(buf[i] & 0x02) count++;
      if(buf[i] & 0x01) count++;
    }
  }

  // leading non-aligned bytes
  var mod = buf.length % bytecount;
  while(c < mod) {
    addBitCount(buf.slice(c, c + 1));
    c++;
  }

  // aligned bytes
  while(c < buf.length) {
    addBitCount(buf.slice(c, c + bytecount));
    c += bytecount;
  }
  return count;
}
417538
@Override
    @SuppressWarnings("unchecked")
    public Object getUndefined(Object key) {
        // Math.abs(x % n) is the same as (x & n-1) when n is a power of 2
        int hashModMask = OpenAddressing.hashTableLength(hashTable) - 1;
        int hash = hashCode(key);
        int bucket = hash & hashModMask;

        int hashEntry = OpenAddressing.getHashEntry(hashTable, bucket) * 2;

        // We found an entry at this hash position
        while (hashEntry >= 0) {
            if (Utils.equal(keysAndValues[hashEntry], key)) {
                return (V) keysAndValues[hashEntry + 1];
            }

            // linear probing resolves collisions.
            bucket = (bucket + 1) & hashModMask;
            hashEntry = OpenAddressing.getHashEntry(hashTable, bucket) * 2;
        }
        return AbstractArrayMap.undefined;
    }
525608
def bucket_value(index, type = nil)
      case type
      when :begin, :start, :lower, :lower_bound then bucket_lower_bound(index)
      when :end, :finish, :upper, :upper_bound then  bucket_upper_bound(index)
      else bucket_average_value(index)
      end
    end
188913
function (key) {
            var hash = hashFunction(key), ret = false;
            var bucket = null;
            if ((bucket = this.__map[hash]) != null) {
                ret = bucket.find(key) != null;
            }
            return ret;
        }
723532
protected boolean isSpace(String bucketName) {
        boolean isSpace = false;
        // According to AWS docs, the access key (used in DuraCloud as a
        // prefix for uniqueness) is a 20 character alphanumeric sequence.
        if (bucketName.matches("[\\w]{20}[.].*")) {
            isSpace = true;
        }
        return isSpace;
    }
1231645
function strlen(key, req) {
  var val = this.getKey(key, req);
  if(!val) return 0;
  if(val instanceof Buffer) return val.length;
  // redis compatible, return byte length
  return Buffer.byteLength(val);
}
1036884
public String generateTemporaryToken(String key, int secondsToLive, Object context) {
    checkNotNull(key);
    String token = tokenGenerator.generate();
    tokenCache.put(key, Triplet.of(token, DateTime.now().plusSeconds(secondsToLive).getMillis(), context));
    return token;
  }
720916
function genStorageKey (ns, key) {
  return (ns === '') ? ns.concat(key) : ns.concat('.').concat(key);
}
391023
function getValueBucket(val) {
  if (val === null) {
    return 'null';
  }
  var bucket = typeof val;
  if (bucket === 'object') {
    // Could be bytes, fixed, array, map, or record.
    if (Array.isArray(val)) {
      return 'array';
    } else if (Buffer.isBuffer(val)) {
      return 'buffer';
    }
  }
  return bucket;
}
307520
private Object syncGetValueFromBucket(FastSyncHashBucket hb, int key, boolean remove) {
        FastSyncHashEntry e = null;
        FastSyncHashEntry last = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "syncGetValueFromBucket: key, remove " + key + " " + remove);
        }
        synchronized (hb) {
            e = hb.root;
            while (e != null) {
                if (e.key == key) {
                    if (remove) {
                        if (last == null) {
                            // this is root
                            hb.root = e.next;
                        } else {
                            last.next = e.next;
                        }
                    }
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                        Tr.exit(tc, "syncGetValueFromBucket: found value in bucket");
                    }
                    return e.value;
                }
                last = e;
                e = e.next;
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "syncGetValueFromBucket-returned null");
        }
        return null;
    }
562726
function(key) {
  this.buffer = new Uint8Array(16);
  this.r = new Uint16Array(10);
  this.h = new Uint16Array(10);
  this.pad = new Uint16Array(8);
  this.leftover = 0;
  this.fin = 0;

  var t0, t1, t2, t3, t4, t5, t6, t7;

  t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0                     ) & 0x1fff;
  t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 <<  3)) & 0x1fff;
  t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 <<  6)) & 0x1f03;
  t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>>  7) | (t3 <<  9)) & 0x1fff;
  t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>>  4) | (t4 << 12)) & 0x00ff;
  this.r[5] = ((t4 >>>  1)) & 0x1ffe;
  t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 <<  2)) & 0x1fff;
  t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 <<  5)) & 0x1f81;
  t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>>  8) | (t7 <<  8)) & 0x1fff;
  this.r[9] = ((t7 >>>  5)) & 0x007f;

  this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
  this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
  this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
  this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
  this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
  this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
  this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
  this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
}