Array

From CometPublic

Jump to: navigation, search

Comet supports one-dimentional arrays of objects of any type. For instance, the declaration

   int x[1..10];

declares x as an array of 10 integers indexed between 1 and 10. Comet arrays are objects and conform to the following API

   class array{T} {
      int low();
      int getLow();     // same semantics as low()
      int up();
      int getHigh();    // same semantics as up()
      int sz();
      int getSize();     // same semantics as sz()
      void setName(string);
      range rng();
      range getRange();  // same semantics as rng()
      void exclud();
      void includ();
      int[] sortPerm();
   }

The sortPerm method returns an array of integers ranging in rng() whose values represent a permutation of the elements of the array corresponding to a sorted order (monotonically increasing).

An array can be defined extensively if one knows the dimension a priori:

     int vs[1..3] = [1,3,5];

It may also be initialized with an expression:

     int vs[i in 1..10] = i * 2;