|
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.
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, any fields in a cluster that are specified in the findrow()
function are automatically converted and maintained as key fields from that
point forward. These key fields are dynamically managed by sheerpower and
do not require unique values. Additionally, the content of key fields can be
changed at any time, offering flexibility in how data is organized and accessed
within a cluster. This feature allows developers to efficiently search and
manipulate data without the need for predefined key fields.
Additionally, any data type can be used as a key.
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. |