-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-5932][CORE] Use consistent naming for size properties #5574
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
d7a06b8
a99032f
e92caf7
8be2f83
733ec9f
dfec4da
0e1567c
15e8dea
270cfe3
cb0c6b7
8c884fa
1dc0444
db9a963
5390fd9
09ea450
747393a
a9f4fcf
851d691
475370a
0cdff35
b809a78
eba4de6
1fbd435
2d15681
ae7e9f6
afc9a38
7a6c847
5d29f90
928469e
35a7fa7
0f4443e
f15f209
f32bc01
69e2f20
54b78b4
c7803cd
fe286b4
d3d09b6
84a2581
8b43748
e428049
3dfae96
22413b1
9ee779c
852a407
fc85733
2ab886b
49a8720
11f6999
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 |
|---|---|---|
|
|
@@ -28,9 +28,18 @@ private ByteUnit(long multiplier) { | |
| this.multiplier = multiplier; | ||
| } | ||
|
|
||
| public long convert(long d, ByteUnit u) { return toBytes(d) / u.multiplier; } | ||
| // Interpret the provided number (d) with suffix (u) as this unit type. | ||
| // E.g. KiB.interpret(1, MiB) interprets 1MiB as its KiB representation = 1024k | ||
| public long interpret(long d, ByteUnit u) { | ||
| return u.toBytes(d) / multiplier; | ||
| } | ||
|
|
||
| // Convert the provided number (d) interpreted as this unit type to unit type (u). | ||
| public long convert(long d, ByteUnit u) { | ||
| return toBytes(d) / u.multiplier; | ||
|
Contributor
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. If you want to be really correct here, you could avoid overflows by playing with the multipliers instead of converting things to bytes first. I think what's bugging me is that the semantics of all these methods are a little weird. It seems like you're trying to cap the maximum amount to be represented to
Contributor
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 saw your comment about using double - I don't think that's a great idea because doubles lose precision as you try to work with values at different orders of magniture. Regarding the last paragraph of my comment above, I don't think it's going to be an issue in practice; but the code here can be changed to at least avoid overflows where possible. I checked |
||
| } | ||
|
|
||
| public long toBytes(long d) { return multiplier * d; } | ||
| public long toBytes(long d) { return x(d, multiplier); } | ||
| public long toKiB(long d) { return convert(d, KiB); } | ||
| public long toMiB(long d) { return convert(d, MiB); } | ||
| public long toGiB(long d) { return convert(d, GiB); } | ||
|
|
@@ -46,6 +55,7 @@ private ByteUnit(long multiplier) { | |
| * This has a short name to make above code more readable. | ||
|
Contributor
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. There's only one call to this method.
|
||
| */ | ||
| static long x(long d, long m) { | ||
| if (d == 0) { return 0; } | ||
| long over = MAX / d; | ||
| if (d > over) return Long.MAX_VALUE; | ||
| if (d < -over) return Long.MIN_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.
How about
convertToandconvertFrominstead?