Shard

What is Shard?

Shard is an intuitive container class that allows extended capabilities of Hashes and arrays, as well as extra methods for formatting and aliases.

Methods

Initialization

A shard's initial parameters are the symbols that you can access via method calls (ex Shard.values[0].name) and can be set to any non-iterable. For ease of documenting my code, we'll just use key/val/util.

test1=Shard.new(key,val,util)
Inserting a new segment to a shard

Adding to a shard can be done one of two ways.

test=Shard.new(:key,:val,:util) #initialize the shard

test.insert(-1,'foo',:bar,123)  #inserts at last position
test.insert(0,'foo',:baz,123)   #inserts at position 0
test.values<<['foo',:bar,123]   #this can be cleaned up later
Deleting shard elements

Deleting from a shard is also easily done. The type parameter is automatically converted to a symbol, so it can be any non-iterable that matches an identifier.

test=Shard.new(:key,:val,:util) #initialize the shard
test.add(-1,'foo',:bar,123)     #add to the shard

test.delete('key','foo')        #delete by key
test.delete(:val,':bar')        #delete by value
test.delete(false,0,2)          #delete everything from position 0 to 2
test.delete(:util,123,0,2)      #delete all utils that match 123 from position 0 to 2
Correction

Shards also supply a few formatting methods.

test=Shard.new(:key,:val,:util) #initialize the shard
x.values<<[1,2,3]               #add to the shard manually
=> [[1, 2, 3]]
test.corr                       #convert all manually inserted array to formatted Dict2 Structs
=> [#<struct key=1, val=2, util=3>]
Pruning

Pruning a shard down to its unique identifiers is accomplished using the following aliases, or a raw Shard.prune method call using any combination of the shard identifiers.

Shard.pAll             #prune all
Shard.pruneAll         #alias for pAll
Shard.prune(:key,:val) #prune both keys and values
Cleaning shards

Cleaning a shard using the .clean method returns an Array (nested, if more than one set is selected) of readable sets with all elements in their original types.

Shard.clean      #cleans and returns entire shard
Shard.clean(0)   #cleans and returns shard element at index 0
Shard.clean(0,2) #cleans and returns shard elements at indexes 0 to 2
Listing

Listing shard elements is done with the .list method, like so

Shard.list(:key,0,2)  #returns all keys between index 0 and 2
Shard.listPos(:key,0) #returns the key at index 0
Meta tags

Getting a shard's meta information is done with the following methods or aliases

Shard.meta.all       #return a Hash of all meta tags
Shard.meta.[metatag] #return the supplied metatag's value (can be size, is_empty, num_indentifiers, identifiers, creationStamp, or editStamp)