New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconcile terminology and method naming to 'used/unused segments'; Rename MetadataSegmentManager to MetadataSegmentsManager #7306
Changes from 11 commits
87556bc
e44e199
25de70d
fe13d9c
050bd3b
562f5b4
a6138da
cb6fe7f
164f783
d959bb0
01c4494
06ec389
09fab95
f4774e1
8d5200d
255f320
f34eef0
2ebb23c
ba8ed62
64b0404
231a529
a113231
abad3f3
cb1f3b0
a5840b8
f4283d2
559f2c8
93c12cd
dfc0dbb
553b804
886e580
77fc5e8
1258fa0
15cb9ae
c2c7547
9cd239e
a723553
26a8381
afcd301
1557acc
96bcab7
d934853
c3e488e
f65e654
5e8f3e4
697f0d5
66a23f9
d3882c4
4b9d992
b77a327
d355aa6
718bb23
19b7f3a
2a6bcff
22e71d1
c575e6e
c5d22a0
285ebc9
53f572a
da7667c
91a5c8c
a566b6d
6da0b9d
d0bf20a
10587c1
2ad6dd5
6745f4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,72 +22,62 @@ | |
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Iterators; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.SortedSet; | ||
import java.util.Spliterator; | ||
import java.util.TreeSet; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* An object that clumps together multiple other objects which each represent a shard of some space. | ||
*/ | ||
public class PartitionHolder<T> implements Iterable<PartitionChunk<T>> | ||
{ | ||
private final TreeSet<PartitionChunk<T>> holderSet; | ||
private final TreeMap<PartitionChunk<T>, PartitionChunk<T>> holderMap; | ||
|
||
public PartitionHolder(PartitionChunk<T> initialChunk) | ||
{ | ||
this.holderSet = new TreeSet<>(); | ||
this.holderMap = new TreeMap<>(); | ||
add(initialChunk); | ||
} | ||
|
||
public PartitionHolder(List<PartitionChunk<T>> initialChunks) | ||
{ | ||
this.holderSet = new TreeSet<>(); | ||
this.holderMap = new TreeMap<>(); | ||
for (PartitionChunk<T> chunk : initialChunks) { | ||
add(chunk); | ||
} | ||
} | ||
|
||
public PartitionHolder(PartitionHolder partitionHolder) | ||
public PartitionHolder(PartitionHolder<T> partitionHolder) | ||
{ | ||
this.holderSet = new TreeSet<>(); | ||
this.holderSet.addAll(partitionHolder.holderSet); | ||
this.holderMap = new TreeMap<>(); | ||
this.holderMap.putAll(partitionHolder.holderMap); | ||
} | ||
|
||
public void add(PartitionChunk<T> chunk) | ||
public boolean add(PartitionChunk<T> chunk) | ||
{ | ||
holderSet.add(chunk); | ||
return holderMap.putIfAbsent(chunk, chunk) == null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just replaced
I don't know. This is unprovable from the point of view of the |
||
} | ||
|
||
@Nullable | ||
public PartitionChunk<T> remove(PartitionChunk<T> chunk) | ||
{ | ||
if (!holderSet.isEmpty()) { | ||
// Somewhat funky implementation in order to return the removed object as it exists in the set | ||
SortedSet<PartitionChunk<T>> tailSet = holderSet.tailSet(chunk, true); | ||
if (!tailSet.isEmpty()) { | ||
PartitionChunk<T> element = tailSet.first(); | ||
if (chunk.equals(element)) { | ||
holderSet.remove(element); | ||
return element; | ||
} | ||
} | ||
} | ||
return null; | ||
return holderMap.remove(chunk); | ||
} | ||
|
||
public boolean isEmpty() | ||
{ | ||
return holderSet.isEmpty(); | ||
return holderMap.isEmpty(); | ||
} | ||
|
||
public boolean isComplete() | ||
{ | ||
if (holderSet.isEmpty()) { | ||
if (holderMap.isEmpty()) { | ||
return false; | ||
} | ||
|
||
Iterator<PartitionChunk<T>> iter = holderSet.iterator(); | ||
Iterator<PartitionChunk<T>> iter = holderMap.keySet().iterator(); | ||
|
||
PartitionChunk<T> curr = iter.next(); | ||
|
||
|
@@ -117,7 +107,7 @@ public boolean isComplete() | |
public PartitionChunk<T> getChunk(final int partitionNum) | ||
{ | ||
final Iterator<PartitionChunk<T>> retVal = Iterators.filter( | ||
holderSet.iterator(), | ||
holderMap.keySet().iterator(), | ||
input -> input.getChunkNumber() == partitionNum | ||
); | ||
|
||
|
@@ -127,13 +117,13 @@ public PartitionChunk<T> getChunk(final int partitionNum) | |
@Override | ||
public Iterator<PartitionChunk<T>> iterator() | ||
{ | ||
return holderSet.iterator(); | ||
return holderMap.keySet().iterator(); | ||
} | ||
|
||
@Override | ||
public Spliterator<PartitionChunk<T>> spliterator() | ||
{ | ||
return holderSet.spliterator(); | ||
return holderMap.keySet().spliterator(); | ||
} | ||
|
||
public Iterable<T> payloads() | ||
|
@@ -153,7 +143,7 @@ public boolean equals(Object o) | |
|
||
PartitionHolder that = (PartitionHolder) o; | ||
|
||
if (!holderSet.equals(that.holderSet)) { | ||
if (!holderMap.equals(that.holderMap)) { | ||
return false; | ||
} | ||
|
||
|
@@ -163,14 +153,14 @@ public boolean equals(Object o) | |
@Override | ||
public int hashCode() | ||
{ | ||
return holderSet.hashCode(); | ||
return holderMap.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "PartitionHolder{" + | ||
"holderSet=" + holderSet + | ||
"holderMap=" + holderMap + | ||
'}'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allTimelineEntries
makes me think there's another collection with a subset of "all", but it isn't.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It follows the naming of "allTimelineEntries". I think the logic behind this naming is that it includes overshadowed objects. I've extended the Javadoc of
iterateAllObjects()
to make it clearer.