-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement grouping. First steps towards #6292
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Multi_Value_Key.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Data.Array_Proxy.Array_Proxy | ||
import Standard.Base.Errors.Illegal_State.Illegal_State | ||
|
||
## PRIVATE | ||
An Enso implementation mirroring `OrderedMultiValueKey` and | ||
`UnorderedMultiValueKey` from the Java helpers. | ||
|
||
The ordered part is implemented by delegating to comparators of its elements. | ||
|
||
The unordered part is implemented by delegating to the hahses of elements. | ||
type Multi_Value_Key | ||
## PRIVATE | ||
Key values:Vector | ||
|
||
## PRIVATE | ||
from_row columns row_index = | ||
arr = Array_Proxy.new columns.length column_ix-> | ||
columns . at column_ix . at row_index | ||
values = Vector.from_polyglot_array arr | ||
Multi_Value_Key.Key values | ||
|
||
## PRIVATE | ||
type Multi_Value_Key_Comparator | ||
## PRIVATE | ||
compare x y = | ||
n = x.values.length | ||
if n != y.values.length then Panic.throw (Illegal_State.Error "Multi_Value_Key used with different number of values: " + x.to_text + " vs " + y.to_text) else | ||
go ix = | ||
if ix >= n then Ordering.Equal else | ||
vx = x.values . at ix | ||
vy = y.values . at ix | ||
cmp = (Comparable.from vx).compare vx vy | ||
if cmp != Ordering.Equal then cmp else | ||
@Tail_Call go (ix + 1) | ||
go 0 | ||
|
||
## PRIVATE | ||
hash x = (Comparable.from x.values).hash x.values | ||
|
||
Comparable.from (_:Multi_Value_Key) = Multi_Value_Key_Comparator |