|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectucar.ma2.Range
public final class Range
Represents a set of integers, used as an index for arrays. It should be considered as a subset of the interval of integers [0, length-1] inclusive. For example Range(1:11:3) represents the set of integers {1,4,7,10} Immutable.
Ranges are monotonically increasing. Elements must be nonnegative. EMPTY is the empty Range. VLEN is for variable length dimensions.Note last is inclusive, so standard iteration is
for (int i=range.first(); i<=range.last(); i+= range.stride()) { ... } or use: Range.Iterator iter = timeRange.getIterator(); while (iter.hasNext()) { int index = iter.next(); ... }
Nested Class Summary | |
---|---|
class |
Range.Iterator
|
Field Summary | |
---|---|
static Range |
EMPTY
|
static Range |
VLEN
|
Constructor Summary | |
---|---|
Range(int length)
Create a range starting at zero, with unit stride. |
|
Range(int first,
int last)
Create a range with unit stride. |
|
Range(int first,
int last,
int stride)
Create a range with a specified stride. |
|
Range(Range r)
Copy Constructor |
|
Range(java.lang.String name,
int first,
int last)
Create a named range with unit stride. |
|
Range(java.lang.String name,
int first,
int last,
int stride)
Create a named range with a specified stride. |
|
Range(java.lang.String name,
Range r)
Copy Constructor with name |
Method Summary | |
---|---|
static java.util.List |
appendShape(java.util.List ranges,
int size)
Deprecated. use Section.appendRange(int size) |
static java.lang.String |
checkInRange(java.util.List section,
int[] shape)
Deprecated. use Section.checkInRange(int shape[]) |
Range |
compact()
Create a new Range by compacting this Range by removing the stride. |
Range |
compose(Range r)
Create a new Range by composing a Range that is reletive to this Range. |
static long |
computeSize(java.util.List section)
Deprecated. use Section.computeSize() |
boolean |
contains(int i)
Is the ith element contained in this Range? |
int |
element(int i)
Get ith element |
boolean |
equals(java.lang.Object o)
Range elements with same first, last, stride are equal. |
static java.util.List |
factory(int[] shape)
Deprecated. use Section(int[] shape) |
static java.util.List |
factory(int[] origin,
int[] shape)
Deprecated. use Section(int[] origin, int[] shape) |
int |
first()
|
int |
getFirstInInterval(int start)
Find the smallest element k in the Range, such that k >= first k >= start k <= last k = first + i * stride for some integer i. |
Range.Iterator |
getIterator()
Iterate over Range index Usage: |
java.lang.String |
getName()
Get name |
static int[] |
getOrigin(java.util.List ranges)
Deprecated. use Section.getOrigin() |
static int[] |
getShape(java.util.List ranges)
Deprecated. use Section.getShape() |
int |
hashCode()
Override Object.hashCode() to implement equals. |
int |
index(int elem)
Get the index for this element: inverse of element |
Range |
intersect(Range r)
Create a new Range by intersecting with a Range using same interval as this Range. |
boolean |
intersects(Range r)
Determine if a given Range intersects this one. |
int |
last()
|
int |
length()
Get the number of elements in the range. |
static java.lang.String |
makeSectionSpec(java.util.List ranges)
Deprecated. use Section.toString() |
int |
max()
Deprecated. use last() |
int |
min()
Deprecated. use first() |
static java.util.List |
parseSpec(java.lang.String sectionSpec)
Deprecated. use new Section(String sectionSpec) |
static java.util.List |
setDefaults(java.util.List rangeList,
int[] shape)
Deprecated. use Section.setDefaults(int[] shape) |
Range |
shiftOrigin(int origin)
Create a new Range shifting this range by a constant factor. |
int |
stride()
|
static Range[] |
toArray(java.util.List ranges)
Deprecated. use Section.getRanges() |
static java.util.List |
toList(Range[] ranges)
Deprecated. use Section.getRanges() |
java.lang.String |
toString()
|
static java.lang.String |
toString(java.util.List ranges)
Deprecated. use Section.toString() |
Range |
union(Range r)
Create a new Range by making the union with a Range using same interval as this Range. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Range EMPTY
public static final Range VLEN
Constructor Detail |
---|
public Range(int first, int last) throws InvalidRangeException
first
- first value in rangelast
- last value in range, inclusive
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range(int length)
length
- number of elements in the Rnagepublic Range(java.lang.String name, int first, int last) throws InvalidRangeException
name
- name of Rangefirst
- first value in rangelast
- last value in range, inclusive
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range(int first, int last, int stride) throws InvalidRangeException
first
- first value in rangelast
- last value in range, inclusivestride
- stride between consecutive elements, must be > 0
InvalidRangeException
- elements must be nonnegative: 0 <= first <= last, stride > 0public Range(java.lang.String name, int first, int last, int stride) throws InvalidRangeException
name
- name of Rangefirst
- first value in rangelast
- last value in range, inclusivestride
- stride between consecutive elements, must be > 0
InvalidRangeException
- elements must be nonnegative: 0 <= first <= last, stride > 0public Range(Range r)
r
- copy from herepublic Range(java.lang.String name, Range r)
name
- result namer
- copy from hereMethod Detail |
---|
public Range compose(Range r) throws InvalidRangeException
r
- range reletive to base
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range compact() throws InvalidRangeException
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range shiftOrigin(int origin) throws InvalidRangeException
origin
- subtract this from first, last
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range intersect(Range r) throws InvalidRangeException
r
- range to intersect
InvalidRangeException
- elements must be nonnegativepublic boolean intersects(Range r)
r
- range to intersect
java.lang.UnsupportedOperationException
- if both Ranges have stridespublic Range union(Range r) throws InvalidRangeException
r
- range to add
InvalidRangeException
- elements must be nonnegativepublic int length()
public int element(int i) throws InvalidRangeException
i
- index of the element
InvalidRangeException
- i must be: 0 <= i < lengthpublic int index(int elem) throws InvalidRangeException
elem
- the element of the range
InvalidRangeException
- if illegal elempublic boolean contains(int i)
i
- index in the original Range
public int first()
public int last()
public int stride()
public java.lang.String getName()
public Range.Iterator getIterator()
Iterator iter = range.getIterator(); while (iter.hasNext()) { int index = iter.next(); doSomething(index); }
public int getFirstInInterval(int start)
start
- starting index
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int min()
public int max()
public static java.util.List factory(int[] shape)
public static java.util.List setDefaults(java.util.List rangeList, int[] shape)
public static java.util.List factory(int[] origin, int[] shape) throws InvalidRangeException
InvalidRangeException
public static int[] getShape(java.util.List ranges)
public static java.lang.String toString(java.util.List ranges)
public static long computeSize(java.util.List section)
section
- List of Range objects
public static java.util.List appendShape(java.util.List ranges, int size) throws InvalidRangeException
ranges
- list of Rangesize
- add this Range
InvalidRangeException
- if size < 1public static int[] getOrigin(java.util.List ranges)
public static Range[] toArray(java.util.List ranges)
public static java.util.List toList(Range[] ranges)
public static java.lang.String makeSectionSpec(java.util.List ranges)
public static java.util.List parseSpec(java.lang.String sectionSpec) throws InvalidRangeException
sectionSpec := dims dims := dim | dim, dims dim := ':' | slice | start ':' end | start ':' end ':' stride slice := INTEGER start := INTEGER stride := INTEGER end := INTEGER where nonterminals are in lower case, terminals are in upper case, literals are in single quotes. Meaning of index selector : ':' = all slice = hold index to that value start:end = all indices from start to end inclusive start:end:stride = all indices from start to end inclusive with given stride
sectionSpec
- the token to parse, eg "(1:20,:,3,10:20:2)", parenthesis optional
java.lang.IllegalArgumentException
- when sectionSpec is misformed
InvalidRangeException
public static java.lang.String checkInRange(java.util.List section, int[] shape)
section
- shape
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |