Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Apache ZooKeeper 3.7.0 Server Source Code
Apache ZooKeeper is an open-source server which enables highly reliable distributed coordination.
Apache ZooKeeper Server Source Code files are provided in the source packge (apache-zookeeper-3.7.0.tar.gz). You can download it at Apache ZooKeeper Website.
You can also browse Apache ZooKeeper Server Source Code below:
✍: FYIcenter.com
⏎ org/apache/zookeeper/server/util/BitHashSet.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.zookeeper.server.util; import java.util.BitSet; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * Using BitSet to store all the elements, and use HashSet to cache limited * number of elements to find a balance between memory and time complexity. * * Without HashSet, we need to use O(N) time to get the elements, N is * the bit numbers in elementBits. But we need to keep the size small to make * sure it doesn't cost too much in memory, there is a trade off between * memory and time complexity. * * Previously, was deciding to dynamically switch between SparseBitSet and * HashSet based on the memory consumption, but it will take time to copy * data over and may have some herd effect of keep copying data from one * data structure to anther. The current solution can do a very good job * given most of the paths have limited number of elements. */ public class BitHashSet implements Iterable<Integer> { /** * Change to SparseBitSet if we we want to optimize more, the number of * elements on a single server is usually limited, so BitSet should be * fine. */ private final BitSet elementBits = new BitSet(); /** * HashSet is used to optimize the iterating, if there is a single * element in this BitHashSet, but the bit is very large, without * HashSet we need to go through all the words before return that * element, which is not efficient. */ private final Set<Integer> cache = new HashSet<Integer>(); private final int cacheSize; // To record how many elements in this set. private int elementCount = 0; public BitHashSet() { this(Integer.getInteger("zookeeper.bitHashCacheSize", 10)); } public BitHashSet(int cacheSize) { this.cacheSize = cacheSize; } public synchronized boolean add(Integer elementBit) { if (elementBit == null || elementBits.get(elementBit)) { return false; } if (cache.size() < cacheSize) { cache.add(elementBit); } elementBits.set(elementBit); elementCount++; return true; } /** * Remove the watches, and return the number of watches being removed. */ public synchronized int remove(Set<Integer> bitSet, BitSet bits) { cache.removeAll(bitSet); elementBits.andNot(bits); int elementCountBefore = elementCount; elementCount = elementBits.cardinality(); return elementCountBefore - elementCount; } public synchronized boolean remove(Integer elementBit) { if (elementBit == null || !elementBits.get(elementBit)) { return false; } cache.remove(elementBit); elementBits.clear(elementBit); elementCount--; return true; } public synchronized boolean contains(Integer elementBit) { if (elementBit == null) { return false; } return elementBits.get(elementBit); } public synchronized int size() { return elementCount; } /** * This function is not thread-safe, need to synchronized when * iterate through this set. */ @Override public Iterator<Integer> iterator() { // sample current size at the beginning int currentSize = size(); if (cache.size() == currentSize) { return cache.iterator(); } return new Iterator<Integer>() { int returnedCount = 0; int bitIndex = 0; @Override public boolean hasNext() { return returnedCount < currentSize; } @Override public Integer next() { int bit = elementBits.nextSetBit(bitIndex); bitIndex = bit + 1; returnedCount++; return bit; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } // visible for test public synchronized int cachedSize() { return cache.size(); } public synchronized boolean isEmpty() { return elementCount == 0; } }
⏎ org/apache/zookeeper/server/util/BitHashSet.java
Or download all of them as a single archive file:
File name: zookeeper-server-3.7.0-fyi.zip File size: 871011 bytes Release date: 2021-05-17 Download
⇒ Apache ZooKeeper 3.7.0 Jute Source Code
⇐ Download Apache ZooKeeper 3.7.0 Source Package
2022-11-16, 13490👍, 0💬
Popular Posts:
commons-lang-1.0.1.jar is the JAR file for Apache Commons Lang 1.0.1, which provides a host of helpe...
commons-collections4-4.4 -sources.jaris the source JAR file for Apache Commons Collections 4.2, whic...
How to download and install ojdbc11.jar for Oracle 21c? ojdbc11.jar for Oracle 21c is a Java JDBC Dr...
What Is commons-codec-1.4.jar? commons-codec-1.4.jar is the JAR file for Apache Commons Codec 1.4, w...
ANTLR is a powerful parser generator for multiple programming languages including Java. ANTLR contai...