-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-1627: New class to handle collection of BufferLedger(s) within … #1150
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
Conversation
| * .netty.buffer package. | ||
| */ | ||
| public class BufferLedger { | ||
| public class BufferLedger implements ValueWithKeyIncluded { |
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.
Let's make ValueWithKeyIncluded be generic so it can return BaseAllocator in this case.
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.
done
| /* | ||
| * The internal data structure to hold values. | ||
| */ | ||
| transient Object[] elementData; |
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.
Let's make all the fields private.
Also, no reason to use transient as we aren't using Java serialization.
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.
done
| * 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove strange comment
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.
Also, let's just not support not null values. Should simplify things.
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.
done
| * {@code false} otherwise. | ||
| */ | ||
| public boolean containsKey(Object key) { | ||
| if (key == null) { |
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.
Let's just throw exception if use passes in null for key.
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.
done
| * @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a typed interface. E.g. containsValue(V value)
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, let's throw illegal if user tries to look for null value.
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.
done
| * @return the value of the mapping with the specified key. | ||
| */ | ||
| public V get(Object key) { | ||
| if (key == null) { |
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.
disallow nulls
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.
done
| * {@code null} if there was no such mapping. | ||
| */ | ||
| public V put(V value) { | ||
| Object _key = value.getKey(); |
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.
Reject an insertion of null here.
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.
done
| * 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as requested above, let's make this a generic interface so getKey is typed.
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.
done
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add comment here on why we use this structure.
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.
done
jacques-n
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to declare K since V already declares it.
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.
done
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One general comment/question. Otherwise looks good.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm - it does not like angle brackets in comments:
public <K> V contains(K key)
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.
same question as above
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm - it does not like angle brackets in comments:
public <K> V get(K key)
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.
we can remove this function, right?
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.
sure
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.
should this be equals() since we're comparing values?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <yuliya@dremio.com> 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 <ivan.sadikov@team.telstra.com> 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 <ivan.sadikov@team.telstra.com> 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 <yuliya@dremio.com> 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 <ivan.sadikov@team.telstra.com> 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.