![]() |
|
A cluster array in Sheerpower is similar to an in-memory spreadsheet, containing rows and columns of data. These clusters can efficiently store and manipulate data, making them ideal for handling information like spreadsheets.
Sheerpower includes a rich set of features that allows you to input spreadsheet files directly into clusters and perform various operations such as sorting, including, excluding, and searching much like you would in a database.
Let's create a cluster array called STUDENT
to hold information about
students. Each row in this cluster will represent a different student, and we will track
each student's name, age, and grade level.
The most common method to add data to a cluster is by adding a new row to the end of the cluster using the ADD CLUSTER
statement.
In this case, a new cluster row is established, storing information about the student "Joan Ark," who is 18 years old and in grade level 12.
Reset cluster
and delete from cluster
for details.
To remove all rows from a cluster — commonly used when reloading data — use:
delete from cluster xxx: all
where xxx
is the cluster name.
The row added last is considered the current row. For example, after the above code, row three (Desmond Jones) is current.
To print information about row one, you first make row one current:
To find out how many rows are in a cluster, use the SIZE()
function:
To ask which row is current, use the ASK CLUSTER
statement:
To operate on each row in a cluster array, use the COLLECT
and END COLLECT
statements.
For example, to print the name, age, and grade level of each student and
calculate their average age:
Sheerpower makes it easy to filter and sort data within a cluster array. Here's how you can do it:
collect
and end collect
block.include
and exclude
statements.
For example, you might filter to include only students over 16 years old.sort
statements must be placed after the filtering. The default sort order is ascending.sort descending
statement.include
, exclude
, and sort
statements
within the collect block to refine your data further.Once the data is collected and sorted, you can iterate through the records using the
for each
statement:
To include only students older than 16:
Use the FINDROW()
function to search a cluster array for specific data:
The FINDROW()
function is highly optimized, capable of
performing over 10 million searches per second, making it ideal for tasks requiring fast lookups.
In SheerPower, when you use the findrow()
function with
specific fields in a cluster, those fields are automatically optimized
and treated as key fields. These key fields are managed
dynamically, meaning:
This all enables efficient searching and manipulation of data in clusters without requiring developers to predefine or rigidly maintain key fields.
Cluster arrays in SheerPower act like in-memory spreadsheets, organizing data into rows and columns. They simplify data management with features like dynamic resizing, key-value manipulation, and efficient searching. Cluster arrays can be extremely large. If your computer has sufficient RAM and pagefile space, clusters can support up to one billion rows with key lookup speeds of millions per second.
findrow()
.Cluster arrays combine flexibility and performance, making them essential for efficient data handling in SheerPower applications.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |