ARROW-1627: New class to handle collection of BufferLedger(s) within …#1150
ARROW-1627: New class to handle collection of BufferLedger(s) within …#1150yufeldman wants to merge 1 commit intoapache:masterfrom
Conversation
| * .netty.buffer package. | ||
| */ | ||
| public class BufferLedger { | ||
| public class BufferLedger implements ValueWithKeyIncluded { |
There was a problem hiding this comment.
Let's make ValueWithKeyIncluded be generic so it can return BaseAllocator in this case.
| /* | ||
| * The internal data structure to hold values. | ||
| */ | ||
| transient Object[] elementData; |
There was a problem hiding this comment.
Let's make all the fields private.
Also, no reason to use transient as we aren't using Java serialization.
| * differentiate a literal 'null' from an empty spot in the | ||
| * map. | ||
| */ | ||
| private static final Object NULL_OBJECT = new Object(); //$NON-LOCK-1$ |
There was a problem hiding this comment.
Also, let's just not support not null values. Should simplify things.
| * {@code false} otherwise. | ||
| */ | ||
| public boolean containsKey(Object key) { | ||
| if (key == null) { |
There was a problem hiding this comment.
Let's just throw exception if use passes in null for key.
| * @return {@code true} if this map contains the specified value, | ||
| * {@code false} otherwise. | ||
| */ | ||
| public boolean containsValue(Object value) { |
There was a problem hiding this comment.
Let's make this a typed interface. E.g. containsValue(V value)
There was a problem hiding this comment.
I know we don't follow Map iface, but just a note that in Map iface it is:
boolean containsValue(Object value)
If we follow the same pattern of "typing" we may also consider do it for other methods (get, remove, containsKey)
| */ | ||
| public boolean containsValue(Object value) { | ||
| if (value == null) { | ||
| value = NULL_OBJECT; |
There was a problem hiding this comment.
As above, let's throw illegal if user tries to look for null value.
| * @return the value of the mapping with the specified key. | ||
| */ | ||
| public V get(Object key) { | ||
| if (key == null) { |
| * {@code null} if there was no such mapping. | ||
| */ | ||
| public V put(V value) { | ||
| Object _key = value.getKey(); |
There was a problem hiding this comment.
Reject an insertion of null here.
| * Helper Iface to generify a value to be included in the map where | ||
| * key is part of the value | ||
| */ | ||
| public interface ValueWithKeyIncluded { |
There was a problem hiding this comment.
as requested above, let's make this a generic interface so getKey is typed.
| private final int size; | ||
| private final UnsafeDirectLittleEndian underlying; | ||
| private final IdentityHashMap<BufferAllocator, BufferLedger> map = new IdentityHashMap<>(); | ||
| private final LowCostIdentityHasMap<BufferLedger> map = new LowCostIdentityHasMap<>(); |
There was a problem hiding this comment.
Let's add comment here on why we use this structure.
jacques-n
left a comment
There was a problem hiding this comment.
One small comment, otherwise looks good.
| * @param <V> | ||
| */ | ||
| public class LowCostIdentityHasMap<V extends ValueWithKeyIncluded> { | ||
| public class LowCostIdentityHasMap<K, V extends ValueWithKeyIncluded<K>> { |
There was a problem hiding this comment.
No need to declare K since V already declares it.
|
Can you please rebase? I just rebased master after 0.7.1 release |
bcc4c71 to
fada2b5
Compare
jacques-n
left a comment
There was a problem hiding this comment.
One general comment/question. Otherwise looks good.
There was a problem hiding this comment.
Isn't there a way to make this typed without requiring two fields in the class type definition?
There was a problem hiding this comment.
The only thing that can be done is : public V get(K key)
But in this case it is quite detached from "K" defined in
ValueWithKeyIncluded
There was a problem hiding this comment.
Hmmm - it does not like angle brackets in comments:
public <K> V contains(K key)
There was a problem hiding this comment.
The only thing that can be done is : public V get(K key)
But in this case it is quite detached from "K" defined in
ValueWithKeyIncluded
There was a problem hiding this comment.
Hmmm - it does not like angle brackets in comments:
public <K> V get(K key)
There was a problem hiding this comment.
we can remove this function, right?
There was a problem hiding this comment.
should this be equals() since we're comparing values?
There was a problem hiding this comment.
not really - IdentityHashMap compares references for both keys and values. Unless we want to change the behavior
jacques-n
left a comment
There was a problem hiding this comment.
Lgtm. +1 Thanks @yufeldman!
…AllocationManager LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger) To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey() BufferLedger provides implementation for it. LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap. ARROW-1627: Small improvement in hashing function. ARROW-1627: Addressing review comments
6cf4810 to
dcd5e29
Compare
|
Merging, thanks for your contribution @yufeldman! |
…AllocationManager LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger) To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey() BufferLedger provides implementation for it. LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap. Author: Yuliya Feldman <[email protected]> Closes apache#1150 from yufeldman/ARROW-1627-master and squashes the following commits: dcd5e29 [Yuliya Feldman] ARROW-1627: New class to handle collection of BufferLedger(s) within AllocationManager LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger) To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey() BufferLedger provides implementation for it. LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap.
|
@wesm Should it be |
|
Good catch - spelling error |
|
Would it be okay to just open small PR without JIRA to fix this? |
JIRA: https://issues.apache.org/jira/browse/ARROW-1869 This PR fixes spelling error in class name for `LowCostIdentityHashMap`. Follow-up for #1150. Author: Ivan Sadikov <[email protected]> Closes #1372 from sadikovi/fix-low-cost-identity-hash-map and squashes the following commits: e3529f6 [Ivan Sadikov] fix low cost identity hash map name
JIRA: https://issues.apache.org/jira/browse/ARROW-1869 This PR fixes spelling error in class name for `LowCostIdentityHashMap`. Follow-up for #1150. Author: Ivan Sadikov <[email protected]> Closes #1372 from sadikovi/fix-low-cost-identity-hash-map and squashes the following commits: e3529f6 [Ivan Sadikov] fix low cost identity hash map name
…AllocationManager LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger) To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey() BufferLedger provides implementation for it. LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap. Author: Yuliya Feldman <[email protected]> Closes apache#1150 from yufeldman/ARROW-1627-master and squashes the following commits: dcd5e29 [Yuliya Feldman] ARROW-1627: New class to handle collection of BufferLedger(s) within AllocationManager LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger) To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey() BufferLedger provides implementation for it. LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap.
JIRA: https://issues.apache.org/jira/browse/ARROW-1869 This PR fixes spelling error in class name for `LowCostIdentityHashMap`. Follow-up for apache#1150. Author: Ivan Sadikov <[email protected]> Closes apache#1372 from sadikovi/fix-low-cost-identity-hash-map and squashes the following commits: e3529f6 [Ivan Sadikov] fix low cost identity hash map name
…AllocationManager
LowCostIdentityHashMap uses array only to store objects since key (BaseAllocator) is already included in the value (BufferLedger)
To make this class a bit more generic it uses values that implement ValueWithKeyIncluded interface that provides API : getKey()
BufferLedger provides implementation for it.
LowCostIdentityHashMap is not general purpose map it just provides some “map like” APIs to simplify switch over from IdentityHashMap.