-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23913][SQL] Add array_intersect function #21102
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
Changes from 1 commit
bc5a02d
c7f230d
e96ab2d
49bc319
4ec43b1
2c30351
74103ce
387d0ca
e374aa9
e31f7e6
9818ba9
352743f
89a828b
90fecd5
663358e
3ef99b8
3462b98
cf742d4
6fba1ee
ce755e2
33781b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,9 +89,13 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| protected var _capacity = nextPowerOf2(initialCapacity) | ||
| protected var _mask = _capacity - 1 | ||
| protected var _size = 0 | ||
| protected var _occupied = 0 | ||
| protected var _growThreshold = (loadFactor * _capacity).toInt | ||
| def g: Int = _growThreshold | ||
| def o: Int = _occupied | ||
|
|
||
| protected var _bitset = new BitSet(_capacity) | ||
| protected var _bitsetDeleted: BitSet = null | ||
|
||
|
|
||
| def getBitSet: BitSet = _bitset | ||
|
|
||
|
|
@@ -122,9 +126,13 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| * Remove an element from the set. If an element does not exists in the set, nothing is done. | ||
| */ | ||
| def remove(k: T): Unit = { | ||
| if (_bitsetDeleted == null) { | ||
| _bitsetDeleted = new BitSet(_capacity) | ||
| } | ||
| val pos = getPos(k) | ||
| if (pos != INVALID_POS && _bitset.get(pos)) { | ||
| if (pos != INVALID_POS) { | ||
| _bitset.unset(pos) | ||
| _bitsetDeleted.set(pos) | ||
| _size -= 1 | ||
| } | ||
| } | ||
|
|
@@ -152,19 +160,24 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| var delta = 1 | ||
| while (true) { | ||
| if (!_bitset.get(pos)) { | ||
| // This is a new key. | ||
| _data(pos) = k | ||
| _bitset.set(pos) | ||
| _size += 1 | ||
| return pos | NONEXISTENCE_MASK | ||
| if (_bitsetDeleted == null || !_bitsetDeleted.get(pos)) { | ||
| // This is a new key. | ||
| _data(pos) = k | ||
| _bitset.set(pos) | ||
| if (_bitsetDeleted != null) { | ||
| _bitsetDeleted.unset(pos) | ||
| } | ||
| _size += 1 | ||
| _occupied += 1 | ||
| return pos | NONEXISTENCE_MASK | ||
| } | ||
| } else if (_data(pos) == k) { | ||
| // Found an existing key. | ||
| return pos | ||
| } else { | ||
| // quadratic probing with values increase by 1, 2, 3, ... | ||
| pos = (pos + delta) & _mask | ||
| delta += 1 | ||
| } | ||
| // quadratic probing with values increase by 1, 2, 3, ... | ||
| pos = (pos + delta) & _mask | ||
| delta += 1 | ||
| } | ||
| throw new RuntimeException("Should never reach here.") | ||
| } | ||
|
|
@@ -178,7 +191,7 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| * to a new position (in the new data array). | ||
| */ | ||
| def rehashIfNeeded(k: T, allocateFunc: (Int) => Unit, moveFunc: (Int, Int) => Unit) { | ||
| if (_size > _growThreshold) { | ||
| if (_occupied > _growThreshold) { | ||
|
||
| rehash(k, allocateFunc, moveFunc) | ||
| } | ||
| } | ||
|
|
@@ -191,14 +204,15 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| var delta = 1 | ||
| while (true) { | ||
| if (!_bitset.get(pos)) { | ||
| return INVALID_POS | ||
| if (_bitsetDeleted == null || !_bitsetDeleted.get(pos)) { | ||
| return INVALID_POS | ||
| } | ||
| } else if (k == _data(pos)) { | ||
| return pos | ||
| } else { | ||
| // quadratic probing with values increase by 1, 2, 3, ... | ||
| pos = (pos + delta) & _mask | ||
| delta += 1 | ||
| } | ||
| // quadratic probing with values increase by 1, 2, 3, ... | ||
| pos = (pos + delta) & _mask | ||
| delta += 1 | ||
| } | ||
| throw new RuntimeException("Should never reach here.") | ||
| } | ||
|
|
@@ -219,6 +233,7 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| /** Return the value at the specified position. */ | ||
| def getValueSafe(pos: Int): T = { | ||
| assert(_bitset.get(pos)) | ||
| assert(_bitsetDeleted == null || !_bitsetDeleted.get(pos)) | ||
| _data(pos) | ||
| } | ||
|
|
||
|
|
@@ -274,6 +289,7 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( | |
| } | ||
|
|
||
| _bitset = newBitset | ||
| _bitsetDeleted = null | ||
| _data = newData | ||
| _capacity = newCapacity | ||
| _mask = newMask | ||
|
|
||
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, please use more descriptive and comprehensible names
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.
Oh, sorry for putting this. This is used only for my debugging. This should be removed.