-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
countMissing
from Storage and replace with a new `CountNothi…
…ng` operation. (#9137) Removing another small piece of logic from the storages to it's own operation.
- Loading branch information
1 parent
5e4a7cf
commit 0e2a91c
Showing
15 changed files
with
101 additions
and
91 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
64 changes: 64 additions & 0 deletions
64
std-bits/table/src/main/java/org/enso/table/data/column/operation/CountNothing.java
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,64 @@ | ||
package org.enso.table.data.column.operation; | ||
|
||
import org.enso.table.data.column.storage.ColumnStorage; | ||
import org.enso.table.data.column.storage.ColumnStorageWithNothingMap; | ||
import org.enso.table.data.table.Column; | ||
import org.graalvm.polyglot.Context; | ||
|
||
/** An operation for counting the number of Nothing values in a Column. */ | ||
public class CountNothing { | ||
/** Counts the number of Nothing values in the given column. */ | ||
public static long apply(Column column) { | ||
ColumnStorage storage = column.getStorage(); | ||
return applyToStorage(storage); | ||
} | ||
|
||
/** Counts the number of Nothing values in the given storage. */ | ||
public static long applyToStorage(ColumnStorage storage) { | ||
if (storage instanceof ColumnStorageWithNothingMap withNothingMap) { | ||
return withNothingMap.getIsNothingMap().cardinality(); | ||
} | ||
|
||
Context context = Context.getCurrent(); | ||
long count = 0; | ||
for (long i = 0; i < storage.getSize(); i++) { | ||
if (storage.isNothing(i)) { | ||
count += 1; | ||
} | ||
context.safepoint(); | ||
} | ||
return count; | ||
} | ||
|
||
/** Returns true if any value in the storage is Nothing. */ | ||
public static boolean anyNothing(ColumnStorage storage) { | ||
if (storage instanceof ColumnStorageWithNothingMap withNothingMap) { | ||
return !withNothingMap.getIsNothingMap().isEmpty(); | ||
} | ||
|
||
Context context = Context.getCurrent(); | ||
for (long i = 0; i < storage.getSize(); i++) { | ||
if (storage.isNothing(i)) { | ||
return true; | ||
} | ||
context.safepoint(); | ||
} | ||
return false; | ||
} | ||
|
||
/** Returns true if all values in the storage are Nothing. */ | ||
public static boolean allNothing(ColumnStorage storage) { | ||
if (storage instanceof ColumnStorageWithNothingMap withNothingMap) { | ||
return withNothingMap.getIsNothingMap().nextClearBit(0) >= storage.getSize(); | ||
} | ||
|
||
Context context = Context.getCurrent(); | ||
for (long i = 0; i < storage.getSize(); i++) { | ||
if (!storage.isNothing(i)) { | ||
return false; | ||
} | ||
context.safepoint(); | ||
} | ||
return true; | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
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