• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9909

23 Aug 2023 09:09AM UTC coverage: 47.813% (-0.003%) from 47.816%
#9909

push

travis_ci

web-flow
[To rel/1.2] [IOTDB-6125] Fix DataPartition allocation bug when insert big batch data (#10935)

24 of 24 new or added lines in 4 files covered. (100.0%)

79946 of 167205 relevant lines covered (47.81%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/structure/BalanceTreeMap.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.commons.structure;
21

22
import org.apache.iotdb.commons.utils.TestOnly;
23

24
import java.util.HashMap;
25
import java.util.HashSet;
26
import java.util.Set;
27
import java.util.TreeMap;
28

29
/**
30
 * This class is used to store key-value pairs. It supports the following operations: 1. Put a
31
 * key-value pair. 2. Get key with minimum value.
32
 *
33
 * @param <K> The type of Key
34
 * @param <V> The type of Value, should be Comparable
35
 */
36
public class BalanceTreeMap<K, V extends Comparable<V>> {
37

38
  private final HashMap<K, V> keyValueMap;
39
  private final TreeMap<V, Set<K>> valueKeysMap;
40

41
  public BalanceTreeMap() {
1✔
42
    this.keyValueMap = new HashMap<>();
1✔
43
    this.valueKeysMap = new TreeMap<>();
1✔
44
  }
1✔
45

46
  /**
47
   * Put or modify a key-value pair.
48
   *
49
   * @param key Key
50
   * @param value Value
51
   */
52
  public void put(K key, V value) {
53
    // Update keyValueMap
54
    V oldValue = keyValueMap.put(key, value);
1✔
55

56
    // Update valueKeyMap
57
    if (oldValue != null) {
1✔
58
      Set<K> keysSet = valueKeysMap.get(oldValue);
1✔
59
      keysSet.remove(key);
1✔
60
      if (keysSet.isEmpty()) {
1✔
61
        valueKeysMap.remove(oldValue);
1✔
62
      }
63
    }
64
    valueKeysMap.computeIfAbsent(value, empty -> new HashSet<>()).add(key);
1✔
65
  }
1✔
66

67
  /**
68
   * Get key with minimum value.
69
   *
70
   * @return Key with minimum value
71
   */
72
  public K getKeyWithMinValue() {
73
    return valueKeysMap.firstEntry().getValue().iterator().next();
1✔
74
  }
75

76
  public V get(K key) {
77
    return keyValueMap.getOrDefault(key, null);
1✔
78
  }
79

80
  public Set<K> keySet() {
81
    return keyValueMap.keySet();
×
82
  }
83

84
  public boolean containsKey(K key) {
85
    return keyValueMap.containsKey(key);
1✔
86
  }
87

88
  public int size() {
89
    return keyValueMap.size();
×
90
  }
91

92
  @TestOnly
93
  public void remove(K key) {
94
    V value = keyValueMap.remove(key);
1✔
95
    if (value != null) {
1✔
96
      Set<K> keysSet = valueKeysMap.get(value);
1✔
97
      keysSet.remove(key);
1✔
98
      if (keysSet.isEmpty()) {
1✔
99
        valueKeysMap.remove(value);
1✔
100
      }
101
    }
102
  }
1✔
103

104
  @TestOnly
105
  public boolean isEmpty() {
106
    return keyValueMap.isEmpty() && valueKeysMap.isEmpty();
1✔
107
  }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc