SimileAjax/DataStructure

= SimileAjax Data Structures =

There is no namespace for SimileAjax.DataStructure; instead, three useful classes of data structure are provided: Set, SortedArray, and EventIndex.

Code: http://api.simile-widgets.org/ajax/2.2.1/scripts/data-structure.js

Migration Notes
SimileAjax.Set was changed into Exhibit.Set. The rest of the file seems to be oriented towards Timeline usage and has not been migrated.

Back to SimileAjax.

SimileAjax.Set
A basic mathematical set data structure.

SimileAjax.Set

 * Arguments:
 * a: Array or Set, initial collection
 * Returns: Set
 * Description: Constructor

SimileAjax.Set.prototype.add

 * Arguments:
 * o: object, the object to add
 * Returns: boolean, true if object added, false otherwise
 * Description: Adds the given object to this set if not already present

SimileAjax.Set.prototype.addSet

 * Arguments:
 * set: Set, the set of elements to add
 * Returns: Nothing
 * Description: Adds each element in the given set to this set

SimileAjax.Set.prototype.remove

 * Arguments:
 * o: object, the object to remove
 * Returns: boolean, true if object removed, false otherwise
 * Description: Removes the given element from this set

SimileAjax.Set.prototype.removeSet

 * Arguments:
 * set: Set, the set of elements to remove
 * Returns: Nothing
 * Description: Removes the elements in this set that correspond to the elements in the given set

SimileAjax.Set.prototype.retainSet

 * Arguments:
 * set: Set, the set to intersect
 * Returns: Nothing
 * Description: Removes all elements in this set that are not present in the given set, i.e. modifies this set to the intersection of the two sets.

SimileAjax.Set.prototype.contains

 * Arguments:
 * o: object, the object to test for
 * Returns: boolean, true if in set, false otherwise
 * Description: Returns whether or not the given element exists in this set

SimileAjax.Set.prototype.size

 * Arguments: None
 * Returns: int
 * Description: Returns the number of elements in this set

SimileAjax.Set.prototype.toArray

 * Arguments: None
 * Returns: Array
 * Description: Returns the unordered elements of this set as an array

SimileAjax.Set.prototype.visit

 * Arguments:
 * f: function, the function of the form function(element)
 * Returns: Nothing
 * Description: Iterates through the elements of this set, order unspecified, executing the given function on each element until the function returns true

SimileAjax.SortedArray
A sorted array data structure.

SimileAjax.SortedArray

 * Arguments:
 * compare: function, a function of form function(elmt1, elmt2) that returns a negative integer if elmt1 < elmt2, 0 if equal, a positive integer otherwise
 * initialArray: Array, initial sorted elements for collection; if not an array, initial elements are empty set
 * Returns: SortedArray
 * Description: Constructor

SimileAjax.SortedArray.prototype.add

 * Arguments:
 * elmt: object, element to add
 * Returns: Nothing
 * Description: Adds object in the correct order within the array according to comparator

SimileAjax.SortedArray.prototype.remove

 * Arguments:
 * elmt: object, element to remove
 * Returns: boolean, true if object removed, false if not
 * Description: Removes object from the sorted array

SimileAjax.SortedArray.prototype.removeAll

 * Arguments: None
 * Returns: Nothing
 * Description: Completely empties array

SimileAjax.SortedArray.prototype.elementAt

 * Arguments:
 * index: int, 0-based index in array
 * Returns: object
 * Description: Returns the object at the given index in the array

SimileAjax.SortedArray.prototype.length

 * Arguments: None
 * Returns: int
 * Description: Returns the size of the array

SimileAjax.SortedArray.prototype.find

 * Arguments:
 * compare: function, of the form function(element)
 * Returns: int
 * Description: Use a comparator that already has a comparison element built in, compare against elements in the array until the point in the array the built in element would fit in is found, returning that index

SimileAjax.SortedArray.prototype.getFirst

 * Arguments: None
 * Returns: object
 * Description: Return the first object in the array or null if none

SimileAjax.SortedArray.prototype.getLast

 * Arguments: None
 * Returns: object
 * Description: Return the last object in the array or null if none

SimileAjax.EventIndex
A sorted array of date-indexed events.

SimileAjax.EventIndex

 * Arguments:
 * unit: type, the type of date to use; defaults to NativeDateUnit
 * Returns: EventIndex
 * Description: Constructor

SimileAjax.EventIndex.prototype.getUnit

 * Arguments: None
 * Returns: object
 * Description: Returns the type of date unit set at instantiation

SimileAjax.EventIndex.prototype.getEvent

 * Arguments:
 * id: string, event identifier
 * Returns: object
 * Description: Returns the event identified by id

SimileAjax.EventIndex.prototype.add

 * Arguments:
 * evt: object, an event to add
 * Returns: Nothing
 * Description: Adds the event to the collection

SimileAjax.EventIndex.prototype.removeAll

 * Arguments: None
 * Returns: Nothing
 * Description: Completely empties the collection

SimileAjax.EventIndex.prototype.getCount

 * Arguments: None
 * Returns: int
 * Description: Returns the number of events in the collection

SimileAjax.EventIndex.prototype.getIterator

 * Arguments:
 * startDate: date of unit type, beginning of range the iterator covers (inclusive)
 * endDate: date of unit type, end of range the iterator covers (inclusive)
 * Returns: SimileAjax.EventIndex._Iterator
 * Description: Return an object useful for iterating through events fitting in the given range in ascending order

SimileAjax.EventIndex.prototype.getReverseIterator

 * Arguments:
 * startDate: date of unit type, beginning of range the iterator covers (inclusive)
 * endDate: date of unit type, end of range the iterator covers (inclusive)
 * Returns: SimileAjax.EventIndex._ReverseIterator
 * Description: Return an object useful for iterating backwards through events in the given range

SimileAjax.EventIndex.prototype.getAllIterator

 * Arguments: None
 * Returns: SimileAjax.EventIndex._AllIterator
 * Description: Returns an object useful for iterating through all the events in the set

SimileAjax.EventIndex.prototype.getEarliestDate

 * Arguments: None
 * Returns: date
 * Description: The earliest date in the collection given it isn't empty

SimileAjax.EventIndex.prototype.getLatestDate

 * Arguments: None
 * Returns: date
 * Description: The latest date in the collection given it isn't empty

SimileAjax.EventIndex.prototype._index

 * Arguments: None
 * Returns: Nothing
 * Description: For each event, we want to find the earliest preceding event that overlaps with it, if any

SimileAjax.EventIndex._Iterator
Forwards iterator for a given date range.

SimileAjax.EventIndex._Iterator

 * Arguments:
 * events: SimileAjax.EventIndex
 * startDate: beginning of date range
 * endDate: end of date range
 * unit: type of dates used
 * Returns: SimileAjax.EventIndex._Iterator
 * Description: Constructor

SimileAjax.EventIndex._Iterator.prototype.hasNext

 * Arguments: None
 * Returns: boolean, true if there are more objects to iterate through, false otherwise
 * Description: Indicates whether there still objects left

SimileAjax.EventIndex._Iterator.prototype.next

 * Arguments: None
 * Returns: obj, the next event
 * Description: Returns the next event in the iteration, or null if none are left

SimileAjax.EventIndex._Iterator.prototype._findNext

 * Arguments: None
 * Returns: Nothing
 * Description: Sets up hasNext and next functions by doing the actual locating of next objects

SimileAjax.EventIndex._ReverseIterator
Backwards iterator for a given date range.

SimileAjax.EventIndex._ReverseIterator

 * Arguments:
 * events: SimileAjax.EventIndex
 * startDate: beginning of date range
 * endDate: end of date range
 * unit: type of dates used
 * Returns: SimileAjax.EventIndex._ReverseIterator
 * Description: Constructor

SimileAjax.EventIndex._ReverseIterator.prototype.hasNext

 * Arguments: None
 * Returns: boolean, true if there are more objects to iterate through, false otherwise
 * Description: Indicates whether there still objects left

SimileAjax.EventIndex._ReverseIterator.prototype.next

 * Arguments: None
 * Returns: obj, the next event
 * Description: Returns the next event in the iteration, or null if none are left

SimileAjax.EventIndex._ReverseIterator.prototype._findNext

 * Arguments: None
 * Returns: Nothing
 * Description: Sets up hasNext and next functions by doing the actual locating of next objects

SimileAjax.EventIndex._AllIterator

 * Arguments:
 * events: SimileAjax.EventIndex, events to iterate through
 * Returns: SimileAjax.EventIndex._AllIterator
 * Description: Iterates through every event in an EventIndex

SimileAjax.EventIndex._AllIterator.prototype.hasNext

 * Arguments: None
 * Returns: boolean, true if there are more objects to iterate through, false otherwise
 * Description: Indicates whether there still objects left

SimileAjax.EventIndex._AllIterator.prototype.next

 * Arguments: None
 * Returns: obj, the next event
 * Description: Returns the next event in the iteration, or null if none are left

Back to SimileAjax.