You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by az...@apache.org on 2023/05/22 09:21:02 UTC

[shardingsphere] branch master updated: Remove unused ManualBitSet (#25844)

This is an automated email from the ASF dual-hosted git repository.

azexin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 59a5e3a0fc9 Remove unused ManualBitSet (#25844)
59a5e3a0fc9 is described below

commit 59a5e3a0fc9cc2bcf71a8834d516812ce354bb03
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Mon May 22 17:20:54 2023 +0800

    Remove unused ManualBitSet (#25844)
---
 .../core/ingest/channel/memory/ManualBitSet.java   | 122 ---------------------
 .../ingest/channel/memory/ManualBitSetTest.java    |  75 -------------
 2 files changed, 197 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSet.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSet.java
deleted file mode 100644
index 5540d41f7a7..00000000000
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSet.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.shardingsphere.data.pipeline.core.ingest.channel.memory;
-
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.List;
-
-/**
- * Manual BitSet.
- */
-public final class ManualBitSet {
-    
-    private static final int BIT_SET_SIZE = 1024;
-    
-    private final List<BitSet> bitSets = new ArrayList<>();
-    
-    private long startIndex;
-    
-    /**
-     * Sets the bit at the specified index to true.
-     *
-     * @param bitIndex a bit index
-     */
-    public synchronized void set(final long bitIndex) {
-        int correctIndex = (int) (bitIndex - startIndex);
-        int listIndex = correctIndex / BIT_SET_SIZE;
-        for (int i = bitSets.size(); i <= listIndex; i++) {
-            bitSets.add(new BitSet(BIT_SET_SIZE));
-        }
-        bitSets.get(listIndex).set(correctIndex % BIT_SET_SIZE);
-    }
-    
-    /**
-     * Get BitSet with specified range.
-     *
-     * @param fromIndex from index
-     * @param toIndex to index
-     * @return BitSet
-     */
-    public synchronized BitSet get(final long fromIndex, final long toIndex) {
-        if (fromIndex >= toIndex) {
-            return new BitSet();
-        }
-        BitSet result = new BitSet((int) (toIndex - fromIndex));
-        int correctFromIndex = (int) (fromIndex - startIndex);
-        int correctToIndex = (int) (toIndex - startIndex);
-        int listFromIndex = correctFromIndex / BIT_SET_SIZE;
-        int listToIndex = correctToIndex / BIT_SET_SIZE;
-        for (int i = listFromIndex, k = 0; i <= listToIndex; i++) {
-            if (i >= bitSets.size()) {
-                break;
-            }
-            BitSet bitSet = bitSets.get(i);
-            int begin = i == listFromIndex ? correctFromIndex % BIT_SET_SIZE : 0;
-            int end = i == listToIndex ? correctToIndex % BIT_SET_SIZE : BIT_SET_SIZE;
-            for (int j = begin; j < end; j++) {
-                if (bitSet.get(j)) {
-                    result.set(k, true);
-                }
-                k++;
-            }
-        }
-        return result;
-    }
-    
-    /**
-     * Get end index.
-     *
-     * @param fromIndex from index
-     * @param size true bit size
-     * @return index
-     * @throws IndexOutOfBoundsException index out of bounds exception
-     */
-    public synchronized long getEndIndex(final long fromIndex, final int size) {
-        if (0 == size) {
-            return fromIndex;
-        }
-        int correctIndex = fromIndex < startIndex ? 0 : (int) (fromIndex - startIndex);
-        int listIndex = correctIndex / BIT_SET_SIZE;
-        int count = size;
-        for (int i = listIndex; i < bitSets.size(); i++) {
-            int begin = i == listIndex ? correctIndex % BIT_SET_SIZE : 0;
-            for (int j = begin; j < BIT_SET_SIZE; j++) {
-                if (bitSets.get(i).get(j) && 0 == --count) {
-                    return startIndex + (long) i * BIT_SET_SIZE + j + 1;
-                }
-            }
-        }
-        throw new IndexOutOfBoundsException(String.format("BitSets(%s) do not have enough data from %d count %d", bitSets, correctIndex, size));
-    }
-    
-    /**
-     * Clear expire BitSet.
-     *
-     * @param bitIndex retain bit index
-     */
-    public synchronized void clear(final long bitIndex) {
-        if ((bitIndex - startIndex) > BIT_SET_SIZE) {
-            int count = Math.min(bitSets.size(), (int) ((bitIndex - startIndex) / BIT_SET_SIZE));
-            if (count > 0) {
-                bitSets.subList(0, count).clear();
-                startIndex += (long) count * BIT_SET_SIZE;
-            }
-        }
-    }
-}
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSetTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSetTest.java
deleted file mode 100644
index 25fcd5a3a59..00000000000
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/ManualBitSetTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.shardingsphere.data.pipeline.core.ingest.channel.memory;
-
-import org.junit.jupiter.api.Test;
-import org.mockito.internal.configuration.plugins.Plugins;
-
-import java.util.BitSet;
-import java.util.List;
-import java.util.stream.IntStream;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ManualBitSetTest {
-    
-    @Test
-    void assertGet() {
-        ManualBitSet bitSet = new ManualBitSet();
-        IntStream.range(0, 1024).forEach(bitSet::set);
-        assertFalse(bitSet.get(0, 1023).get(1023));
-        assertTrue(bitSet.get(0, 1024).get(1023));
-        assertFalse(bitSet.get(0, 1024).get(1024));
-        assertFalse(bitSet.get(0, 1025).get(1024));
-    }
-    
-    @Test
-    void assertGetEndIndexSuccess() {
-        ManualBitSet bitSet = new ManualBitSet();
-        IntStream.range(1024, 1100).filter(each -> each % 2 == 1).forEach(bitSet::set);
-        assertThat(bitSet.getEndIndex(0L, 5), is(1034L));
-        bitSet.clear(1025);
-        assertThat(bitSet.getEndIndex(0L, 5), is(1034L));
-    }
-    
-    @Test
-    void assertGetEndIndexFailure() {
-        ManualBitSet bitSet = new ManualBitSet();
-        IntStream.range(0, 10).filter(each -> each % 2 == 1).forEach(bitSet::set);
-        assertThrows(IndexOutOfBoundsException.class, () -> bitSet.getEndIndex(0L, 10));
-    }
-    
-    @Test
-    @SuppressWarnings("unchecked")
-    void assertClear() throws ReflectiveOperationException {
-        ManualBitSet bitSet = new ManualBitSet();
-        IntStream.range(0, 100).forEach(bitSet::set);
-        List<BitSet> bitSets = (List<BitSet>) Plugins.getMemberAccessor().get(ManualBitSet.class.getDeclaredField("bitSets"), bitSet);
-        assertNotNull(bitSets);
-        assertThat(bitSets.size(), is(1));
-        bitSet.clear(1025);
-        assertTrue(bitSets.isEmpty());
-        bitSet.clear(2049);
-        assertTrue(bitSets.isEmpty());
-    }
-}