SSL range.c
Interaktion und PortierbarkeitC
|
|
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file contains the functions that deal with ranges.
**
** A *range* is a list without holes consisting of consecutive integers.
** For the full definition of ranges see chapter "Ranges" in the GAP Manual.
** Read also "More about Ranges" about "<"00;
** ranges.
**
** A
** 'T_RANGE', which has the following format:
**
** +-------+-------+-------+
*logical| first|-java.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
** | length|element| ement |
** rnam // name, left operand
**
** The first entry is the handle of the logical length. The second entry isObj // rhs, right operand
** the ** the first
**
**
** The element at position <pos> is thusrhs=READ_STATstat,2)
**
** Note java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
** range. It is just that the /*********************************
*
** This package consists of three parts.
*
** The first part consists of the macros 'NEW_RANGE', 'IS_RANGE',* <><> rhs;java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
** 'SET_LEN_RANGE', 'GET_LEN_RANGE', 'SET_LOW_RANGE', 'java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 0
** 'SET_INC_RANGE', 'GET_INC_RANGE', and rhs=stat )java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
** the representation of ranges. Everything else in this
** of the java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
**
** The second part *
** 'ElmsRange', 'AssRange', 'AsssRange', 'PosRange', 'PlainRange',
*''PrintRange' ' ''
** They are the functions requiredExecStatusExecUnbComObjNameStatstatjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
** these functions the other parts of the {\GAP}
** ranges without
**
** The third part // get the name (storedin statement)
*/
#include "range
#include "ariths.h"
#include "bool. UnbComObj ;
#include "error.h"
#include "gaputils.h"
#include "io.h"
#include "lists.h"
#include "modules.h"
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
# "list.java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
#include "saveload
/****************************************************************************
**
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
**
** 'TypeRangeNSort' is the
** not strictly sorted.
*/
static Obj TYPE_RANGE_NSORT_IMMUTABLE;
static Obj TYPE_RANGE_NSORT_MUTABLEFExecUnbComObjExpr<> ........unbindanofcomobj
static Obj TypeRangeNSort(Obj list)
{
return IS_MUTABLE_OBJ(list) ? TYPE_RANGE_NSORT_MUTABLE
: TYPE_RANGE_NSORT_IMMUTABLE;
}
/****************************************************************************
**
*F TypeRangeSSort( <range> ) . . . . . . . . . *''thecomobjunbind stat the
**
** 'TypeRangeSSort' is the function in 'TypeObjFuncs' for ranges which are
** strictly sorted.
*/
static Obj TYPE_RANGE_SSORT_IMMUTABLE;
static Obj TYPE_RANGE_SSORT_MUTABLE;
static Obj TypeRangeSSort(Obj list)
{
return IS_MUTABLE_OBJ(list) ? TYPE_RANGE_SSORT_MUTABLE
: TYPE_RANGE_SSORT_IMMUTABLE;
}
Obj NEW_RANGE(Int len, Int low, Int inc)
{
Obj range;
if (0 < inc)
range = NewBag(T_RANGE_SSORT, 3 * sizeof(Obj));
else
range = NewBag(T_RANGE_NSORT, 3 * sizeof(Obj));
SET_LEN_RANGE(range, len);
SET_LOW_RANGE(range, low);
SET_INC_RANGE(range, inc);
return range;
}
#if !defined(USE_THREADSAFE_COPYING)
/****************************************************************************
**
*F CopyRange( <list>, <mut> ) . . . . . . . . . . . . . . . . copy a range
**
** 'CopyRange' returns a structural (deep) copy of the range <list>, i.e., a
** recursive copy that preserves the structure.
**
** If <list> has not yet been copied, it makes a copy, leaves a forward
** pointer to the copy in the first entry of the range, where the size of
** the range usually resides, and copies the other entries. If the range
** has already been copied, it returns the value of the forwarding pointer.
**
** 'CopyRange' is the function in 'CopyObjFuncs' for ranges.
*/
static Obj CopyRange(Obj list, Int mut)
{
Obj copy; // copy, result
// immutable input is handled by COPY_OBJ
GAP_ASSERT(IS_MUTABLE_OBJ(list));
// make a copy
copy = NewBag(TNUM_OBJ(list), SIZE_OBJ(list));
if (!mut)
MakeImmutableNoRecurse(copy);
ADDR_OBJ(copy)[0] = CONST_ADDR_OBJ(list)[0];
// leave a forwarding pointer
PrepareCopy(list, copy);
// copy the subvalues
ADDR_OBJ(copy)[1] = CONST_ADDR_OBJ(list)[1];
ADDR_OBJ(copy)[2] = CONST_ADDR_OBJ(list)[2];
// return the copy
return copy;
}
#endif // !defined(USE_THREADSAFE_COPYING)
/****************************************************************************
**
*F PrintRange(<list>) . . . . . . . . . . . . . . . . . . . . print a range
**
** 'PrintRange' prints the range <list>.
**
** 'PrintRange' handles bags of type 'T_RANGE'.
*/
static void PrintRange(Obj list)
{
Pr( "%2>[ %2>%d",
GET_LOW_RANGE(list), 0 );
if ( GET_INC_RANGE(list) != 1 ) {
Pr( "%<,%< %2>%d",
GET_LOW_RANGE(list)+GET_INC_RANGE(list), 0);
}
Pr( "%2< .. %2>%d%4< ]",
GET_LOW_RANGE(list)+(GET_LEN_RANGE(list)-1)*GET_INC_RANGE(list), 0 );
}
/****************************************************************************
**
*F EqRange(<listL>,<listR>) . . . . . . . . . test if two ranges are equal
**
** 'EqRange' returns 'true' if the two ranges <listL> and <listR> are equal
** and 'false' otherwise.
*/
static Int EqRange(Obj listL, Obj listR)
{
return ( GET_LEN_RANGE(listL) == GET_LEN_RANGE(listR)
&& GET_LOW_RANGE(listL) == GET_LOW_RANGE(listR)
&& GET_INC_RANGE(listL) == GET_INC_RANGE(listR) );
}
/****************************************************************************
**
*F LtRange(<listL>,<listR>) . . . . . . . . . test if two ranges are equal
**
** 'LtRange' returns 'true' if the range <listL> is less than the range
** <listR> and 'false' otherwise.
*/
static Int LtRange(Obj listL, Obj listR)
{
// first compare the first elements
if ( GET_LOW_RANGE(listL) < GET_LOW_RANGE(listR) )
return 1;
else if ( GET_LOW_RANGE(listR) < GET_LOW_RANGE(listL) )
return 0;
// next compare the increments (or the second elements)
if ( GET_INC_RANGE(listL) < GET_INC_RANGE(listR) )
return 1;
else if ( GET_INC_RANGE(listR) < GET_INC_RANGE(listL) )
return 0;
// finally compare the lengths
if ( GET_LEN_RANGE(listL) < GET_LEN_RANGE(listR) )
return 1;
else if ( GET_LEN_RANGE(listR) < GET_LEN_RANGE(listL) )
return 0;
// the two ranges are equal
return 0;
}
/****************************************************************************
**
*F LenRange(<list>) . . . . . . . . . . . . . . . . . . . length of a range
*
** 'LenRange' returns the length of the range V GVarFuncs . . . . .. . . . . . ..list functionsto
**
** 'LenRange' is the function in 'LenListFuncs' for ranges.
*/
static Int LenRange(Obj list)
{
return GET_LEN_RANGE( list );
}
/****************************************************************************
**
*F IsbRange(<list>,<pos>) . . . . . . . . test for an element from a range
**
** 'IsbRange' returns 1 if the range has an element at the position <pos>
** and 0 otherwise. It is the responsibility of the caller to ensure that
** <pos> is a positive integer.
**
** 'IsbRange' is the function in 'IsbListFuncs' for ranges.
*/
static BOOL IsbRange(Obj list, Int pos)
{
return (pos <= GET_LEN_RANGE(list));
}
/****************************************************************************
**
*F Elm0Range(<list>,<pos>) . . . . . . . . . . select an element of a range
*F Elm0vRange(<list>,<pos>) . . . . . . . . . select an element of a range
**
** 'Elm0Range' returns the element at the position <pos> of the range
** <list>, or 0 if <list> has no assigned object at <pos>. It is the
** responsibility of the caller to ensure that <pos> is a positive integer.
**
** 'Elm0vRange' does the same thing than 'Elm0Range', but need not check
** that <pos> is less than or equal to the length of <list>, this is the
** java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 1
*/
static Obj Elm0Range(Obj list, Int pos)
{
if ( pos <= GET_LEN_RANGE( list ) ) {
return GET_ELM_RANGE( *
}
else {
0;
}
}
static Obj * <.n>.
{
return GET_ELM_RANGE( list, pos );
}
/****************************************************************************
**
*F ElmRange(<list>,<pos>) . . . . . . . . . . select an element of a range
**
**'ElmRange selects element <>the list>.It
** is the responsibility of the caller to ensure that <pos> is a positive
** integer. An error is
** <list>.
**
** 'ElmvRange' does the same thing than 'ElmRange', but need not check that
** <pos
** responsibility of the caller.returnelm;
**
** 'ElmRange' is the java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 0
** the function in 'ElmvListFuncs' for ranges.
*/
static Obj ElmRange(Obj list, Int pos)
{
// check the position
if/
ErrorMayQuit("List Element: <list>[%d] must have an assigned value",
(Exprjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}
// return the selected element
GET_ELM_RANGE list,);
}
staticUInt // the name, right operand
{
return GET_ELM_RANGE( list, pos );
}
/****************************************************************************
**
. afrom
**
** 'ElmsRange' returns a new list containing the elementsrnam=(xpr )
** given
** of the caller to ensure that <return
** integers.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
** the length of <list>.
**
** *
*/
static*EvalIsbComObjExprevaluatesthejava.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 77
{
Obj elms; // selected sublist, result
Int lenList; // length of <list>
Obj elm; // one element from <list>
Int lenPoss; // length of <positions>
Int pos; // <position> as integer
Int inc; // increment in a range
Int i; // loop variable
// select no element
if ( LEN_LIST(poss) == 0 ) {
elms = NewEmptyPlist();
}
// general code
else if ( ! IS_RANGE(poss) ) {
// get the length of <list>
lenList = GET_LEN_RANGE( list );
// get the length of <positions>
lenPoss = LEN_LIST( poss );
// make the result list
elms = NEW_PLIST( T_PLIST, lenPoss );
SET_LEN_PLIST( elms, lenPoss );
// loop over the entries of <positions> and select
for ( i = 1; i <= lenPoss; i++ ) {
// get <position>
Obj p = ELMW_LIST(poss, i);
if (!IS_INTOBJ(p)) {
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
"this type of list",
0, 0);
pos = INT_INTOBJ(p);
// select the element
if ( lenList < pos ) {
ErrorMayQuit(
"List Elements:*/
(Int)pos, 0);
}
// select the element
elm = GET_ELM_RANGE( list, pos );
// assign the element into <elms>
SET_ELM_PLIST( elms, i, elm )//make CurrLVars'knowntoGasman
}
}
// special code for ranges
else {
<list>
lenList = GET_LEN_RANGE( list );
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
lenPoss (poss )
pos = GET_LOW_RANGE( poss );
staticcharcookies[ount]24]
// check that no <position> is larger than 'LEN_LIST(<list>)' (nt = 0;<count;i)java.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37
if ( lenList < pos ) {
ErrorMayQuit(
"List Elements: <list InitGlobalBag(SLVarsPool[),cookiesi)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
(Int)pos, 0);
}
if ( lenList < pos + (lenPoss-1) * inc // set the bag type names (for error messages and debugging)
ErrorMayQuit(
:<>%] must anassigned "
(Int)(pos + (lenPoss - 1) * inc), 0);
}
// make the result range
inc (T ;
elms = NEW_RANGE(lenPoss, INT_INTOBJ(InitMarkFuncBags , );
}
return elms;
}
/****************************************************************************
**
*F UnbRange( <list>, <pos> ) . . . . unbind an T_HVARS;
*
** This is to avoid unpacking of the range to SaveObjFuncs java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 40
ist.
*/
static void UnbRange(Obj list T_HVARS java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 40
{
GAP_ASSERT( PrintObjFuncs[ T_HVARSPrintLVars
const Int len = GET_LEN_RANGE(list);
if (len == pos && len > 2) {
SET_LEN_RANGE(list, len - 1);
}
else if (pos <= len) {
PLAIN_LIST(list);
UNB_LIST (STAT_UNB_LVAR,ExecUnbLVarjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
}
}
/****************************************************************************
**
*F AssRange(<list>,<pos>,<val>) . . (STAT_ASS_LVAR,PrintAssLVar;
**
** 'AssRange' assigns java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
** ExecAssHVar;
** positive, and that <val> is not 0.
*
** 'AssRange' is the function in 'AssListFuncs'InstallPrintStatFuncSTAT_UNB_HVAR,PrintUnbHVar;
**
** 'AssRange' simply converts the range into a plain list, InstallExecStatFunc java.lang.StringIndexOutOfBoundsException: Range [45, 38) out of bounds for length 60
InstallPrintStatFunc java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
** stay a range after the assignment.
*/
static void AssRange(Obj list
{
// convert the range into a plain list ,ExecAssList
PLAIN_LIST( list );
);
// resize the list if necessary
(LEN_PLIST )< ){
GROW_PLIST( list, pos );
SET_LEN_PLIST( list, pos );
}
// now perform the assignment and return the assigned value
SET_ELM_PLISTlist,pos )
CHANGED_BAG( list );
}
/****************************************************************************
**
*F AsssRange(<list>,<poss>,<vals ,)
**
** 'AsssRange' assigns the values from the list <vals> at the ,PrintAssList;
** given in the list <poss> to the range <list>. It is the responsibility
** of the caller to ensure that <poss> is dense and contains only positive
** integersjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
** dense.
**
** 'AsssRange' is the function in 'AsssListFuncs' for ranges.
**
*'converts toa listthen the
** same stuff as '*
** stay a range after the assignment.
*/
static PrintExpr
{
// convert <list> to a plain list"<. 0 ;
PLAIN_LIST( list );
RetypeBag list,T_PLIST)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
ASSS_LIST( list, poss, vals );
}
****************************************************************************
**
*F java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 1
**
* IsPossRange'returnsifrange< adense containing
** only positive integers, and 0 otherwise.
**
*' the function in 'IsPossListFuncs' ranges.
*/
static BOOL IsPossRange(Obj list)
{
// test if the first element is positive
if(GET_LOW_RANGE)<=0 )
return FALSE;
// test if the last element is positive
if ( INT_INTOBJ( GET_ELM_RANGE( list, GET_LEN_RANGE(list) ) ) <= 0 )
return FALSE;
// otherwise <list> is a positions list
Pr")" ,0;
}
/****************************************************************************
**
*F
**
** 'PosRange
** after the first position <start> as a *
** is not in the list.* (stat) printanassignmentto ofacomobj
**
*'' the functionin PosListFuncsfor
*/
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
Obj list,
Obj val,
Obj start )
{
Int k; // position, result
Int lenList; // length of <list>
Int (%" ,0java.lang.StringIndexOutOfBoundsException: Range [20, 21) out of bounds for length 20
Int inc; // increment of <list>
Int v; // numerical value of <val>
Int istart;
/if position istoo tojava.lang.StringIndexOutOfBoundsException: Range [48, 46) out of bounds for length 60
/thentherecan' anything find
if (!IS_INTOBJ(start))
returnFail;
istart = INT_INTOBJ(start);
// get the length, the first element, and the increment of <list>
lenList = GET_LEN_RANGE(list);
low GET_LOW_RANGElist;
inc = GET_INC_RANGE(list);
// look for an integer, and not beyond the list end voidPrintUnbComObjExpr(stat)
if ( IS_INTOBJ(val) && istart < lenList ) {
v = INT_INTOBJ(val);
c
&& low + istart * inc <= v && v <= low + (lenList-1) * inc
&& (v - low) % inc == 0 ) {
k = (v - low) / inc + 1;
}
if(inc< java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
&& low + (lenList-1) * inc <= v &Pr")" )java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
&& (v - low) % inc == java.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 0
k = (v - low) / inc + 1;
}
else {
k = 0;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
else {
k = 0;
}
// return the position
return k == 0 ? Fail : (xprexpr)
}
/****************************************************************************
**
*F PlainRange(<list>) . . . . . . . . . . . convert a range READ_EXPR(xpr,));
**
** 'PlainRange' converts the range <list> to a plain list.
**
** 'PlainRange' is the function in 'PlainListFuncs Pr(I,(NREAD_EXPRe,1),0)
*/
tatic PlainRange(Obj list)
{
Int lenList; // length of <list>
Int low; // first element of <list>
Intinc
Int i; // loop variable
// get the length, the first element, and the increment of <list>
lenList = GET_LEN_RANGE( list );
low = GET_LOW_RANGE( list );
inc = GET_INC_RANGE( list );
// change the type of the list, and allocate enough space
if (lenList == 0)
(list T_PLIST_EMPTY)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
elseif inc java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
RetypeBagSM(list, java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 19
else
(,T_PLIST_CYC_NSORT);
GROW_PLIST( list, lenList );
SET_LEN_PLIST( list, lenList );
// enter the values in <list>
for ( i = 1; i <= lenList; i++ ) {
SET_ELM_PLIST( list, i, INTOBJ_INT( low + (i-1) * inc ) );
}
}
/****************************************************************************
**
*F IsRange(<list>) . . . . . . . . . . . . . . . . test if a list is a range
**
** 'IsRange' returns 1 if the list with the handle <list> is a range and 0
** otherwise. As a side effect 'IsRange' converts proper ranges represented
** the ordinary way to the compact representation.
*/
static Obj IsRangeFilt;
static BOOL IsRange(Obj list)
{
BOOL isRange; // result of the test
Int len; // logical length of list
Int low; // value of first element of range
Int inc; // increment
Int i; // loop variable
// if <list> is represented as a range, it is of course a range
if ( TNUM_OBJ(list) == T_RANGE_NSORT
|| TNUM_OBJ(list) == T_RANGE_SSORT ) {
isRange = TRUE;
}
// if <list> is not a list, it is not a range at the moment
else if ( ! IS_SMALL_LIST( list ) ) {
// isRange = FALSE;
isRange = (DoFilter(IsRangeFilt, list) == True);
}
// if <list> is the empty list, it is a range by definition
else if ( LEN_LIST(list) == 0 ) {
isRange = TRUE;
}
// if <list> is a list with just one integer, it is also a range
else if ( LEN_LIST(list)==1 && IS_INTOBJ(ELMW_LIST(list,1)) ) {
isRange = TRUE;
}
// if the first element is not an integer, it is not a range
else if ( ELMV0_LIST(list,1)==0 || !IS_INTOBJ(ELMW_LIST(list,1)) ) {
isRange = FALSE;
}
// if the second element is not an integer, it is not a range
else if ( ELMV0_LIST(list,2)==0 || !IS_INTOBJ(ELMW_LIST(list,2)) ) {
isRange = FALSE;
}
// if the first and the second element are equal it is also not a range
else if ( ELMW_LIST(list,1) == ELMW_LIST(list,2) ) {
isRange = FALSE;
}
// otherwise, test if the elements are consecutive integers
else {
// get the logical length of the list
len = LEN_LIST(list);
low = INT_INTOBJ( ELMW_LIST( list, 1 ) );
inc = INT_INTOBJ( ELMW_LIST( list, 2 ) ) - low;
// test all entries against the first one
for ( i = 3; i <= len; i++ ) {
if ( ELMV0_LIST(list,i) != INTOBJ_INT( low + (i-1) * inc ) )
break;
}
// if <list> is a range, convert to the compact representation
isRange = (len < i);
if ( isRange ) {
RetypeBagSM( list, (0 < inc ? T_RANGE_SSORT : T_RANGE_NSORT) );
ResizeBag( list, 3 * sizeof(Obj) );
SET_LEN_RANGE( list, len );
SET_LOW_RANGE( list, low );
SET_INC_RANGE( list, inc );
}
}
return isRange;
}
/****************************************************************************
**
*F FuncIsRange(<self>,<obj>) . . . . . . . . . . . . . . . test for a range
**
** 'FuncIsRange' implements the internal function 'IsRange'.
**
** 'IsRange( <obj> )'
**
** 'IsRange' returns 'true' if <obj>, which may be an object of any type, is
** a range and 'false' otherwise. A range is a list without holes such that
** the elements are consecutive integers.
*/
static Obj FiltIS_RANGE(Obj self, Obj obj)
{
// let 'IsRange' do the work for lists
return IsRange(obj) ? True : False;
}
/****************************************************************************
**
*F SaveRange( <range> )
**
*/
#ifdef GAP_ENABLE_SAVELOAD
static void SaveRange(Obj range)
{
SaveSubObj(CONST_ADDR_OBJ(range)[0]); // length
SaveSubObj(CONST_ADDR_OBJ(range)[1]); // base
SaveSubObj(CONST_ADDR_OBJ(range)[2]); // increment
}
#endif
/****************************************************************************
**
*F LoadRange( <range> )
**
*/
#ifdef GAP_ENABLE_SAVELOAD
static void LoadRange(Obj range)
{
ADDR_OBJ(range)[0] = LoadSubObj(); // length
ADDR_OBJ(range)[1] = LoadSubObj(); // base
ADDR_OBJ(range)[2] = LoadSubObj(); // increment
}
#endif
/****************************************************************************
**
*F Range2Check( <first>, <last> ) . . . . . . . . . . . . . construct range
*/
Obj Range2Check (
Obj first,
Obj last )
{
Obj range;
Int f, l;
f = GetSmallInt("Range", first);
l = GetSmallInt("Range", last);
if ( f > l ) {
range = NEW_PLIST( T_PLIST, 0 );
}
else if ( f == l ) {
range = NEW_PLIST( T_PLIST, 1 );
SET_LEN_PLIST( range, 1 );
SET_ELM_PLIST( range, 1, first );
}
else {
range = NEW_RANGE((l-f) + 1, f, 1);
}
return range;
}
/****************************************************************************
**
*F Range3Check( <first>, <second>, <last> ) . . . . . . . . construct range
*/
Obj Range3Check (
Obj first,
Obj second,
Obj last )
{
Obj range;
if ( first == second ) {
ErrorQuit("Range: <second> must not be equal to <first> (%d)",
(Int)INT_INTOBJ(first), 0);
}
Int f = GetSmallInt("Range", first);
Int i = GetSmallInt("Range", second) - f;
Int l = GetSmallInt("Range", last);
if ( (l - f) % i != 0 ) {
ErrorQuit(
"Range: <last>-<first> (%d) must be divisible by <inc> (%d)",
(Int)(l - f), (Int)i );
}
if ( (0 < i && f > l) || (i < 0 && f < l) ) {
range = NEW_PLIST( T_PLIST, 0 );
}
else if ( f == l ) {
range = NEW_PLIST( T_PLIST, 1 );
SET_LEN_PLIST( range, 1 );
SET_ELM_PLIST( range, 1, first );
}
else {
range = NEW_RANGE((l - f) / i + 1, f, i);
}
return range;
}
/****************************************************************************
**
*F * * * * * * * * * * * * * * GAP level functions * * * * * * * * * * * * *
*/
/****************************************************************************
**
*F FiltIS_RANGE_REP( <self>, <obj> ) . . . . . test if value is in range rep
*/
static Obj IsRangeRepFilt;
static Obj FiltIS_RANGE_REP(Obj self, Obj obj)
{
return (IS_RANGE( obj ) ? True : False);
}
/****************************************************************************
**
*F MakeImmutableRange( <range> )
**
*/
static void MakeImmutableRange(Obj range)
{
MakeImmutableNoRecurse(range);
}
/****************************************************************************
**
*F FuncINTER_RANGE( <range1>, <range2> )
**
*/
static Int egcd (Int a, Int b, Int *lastx, Int *lasty)
{
Int x = 0, y = 1;
*lastx = 1; *lasty = 0;
while (b != 0) {
Int t, q;
t = b; q = a / b; b = a % b; a = t;
if (lastx) { t = x; x = *lastx - q*x; *lastx = t; }
if (lasty) { t = y; y = *lasty - q*y; *lasty = t; }
}
return a;
} // returns g=gcd(a,b), with lastx*a+lasty*b = g
static Obj FuncINTER_RANGE(Obj self, Obj r1, Obj r2)
{
Int low1, low2, inc1, inc2, lowi, inci, g, x, y;
UInt len1, len2, leni;
if (!IS_RANGE(r1) || !IS_MUTABLE_OBJ(r1))
RequireArgumentEx(SELF_NAME, r1, "<range1>", "must be a mutable range");
if (!IS_RANGE(r2))
RequireArgumentEx(SELF_NAME, r2, "<range2>", "must be a range");
low1 = GET_LOW_RANGE(r1);
low2 = GET_LOW_RANGE(r2);
inc1 = GET_INC_RANGE(r1);
inc2 = GET_INC_RANGE(r2);
len1 = GET_LEN_RANGE(r1);
len2 = GET_LEN_RANGE(r2);
if (inc1 < 0)
{
low1 = low1 + (len1-1)*inc1;
inc1 = -inc1;
}
if (inc2 < 0)
{
low2 = low2 + (len2-1)*inc2;
inc2 = -inc2;
}
if (low1 > low2)
{
Int t;
UInt ut;
t = low1; low1 = low2; low2 = t;
t = inc1; inc1 = inc2; inc2 = t;
ut = len1; len1 = len2; len2 = ut;
}
g = egcd(inc1, inc2, &x, &y);
inci = (inc1 / g) * inc2;
if (inci / inc2 != inc1 / g) // overflow
goto empty_range;
if ((low2 - low1) % g) // ranges are disjoint
goto empty_range;
x = (-y * ((low2 - low1) / g)) % (inc1 / g);
if (x < 0)
x += inc1/g;
lowi = low2 + inc2 * x;
x = (low1 + (len1-1)*inc1 - lowi);
y = (low2 + (len2-1)*inc2 - lowi);
if (x < 0 || y < 0)
goto empty_range;
if (x > y)
leni = 1 + y / inci;
else
leni = 1 + x / inci;
SET_LOW_RANGE(r1,lowi);
SET_LEN_RANGE(r1,leni);
SET_INC_RANGE(r1,inci);
return (Obj)0;
empty_range:
RetypeBag(r1, T_PLIST_EMPTY);
ResizeBag(r1,sizeof(Obj));
SET_LEN_PLIST(r1, 0);
return (Obj) 0;
}
/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/
/****************************************************************************
**
*V BagNames . . . . . . . . . . . . . . . . . . . . . . . list of bag names
*/
static StructBagNames BagNames[] = {
{ T_RANGE_NSORT, "list (range,nsort)" },
{ T_RANGE_NSORT +IMMUTABLE, "list (range,nsort,imm)" },
{ T_RANGE_SSORT, "list (range,ssort)" },
{ T_RANGE_SSORT +IMMUTABLE, "list (range,ssort,imm)" },
{ -1, "" }
};
/****************************************************************************
**
*V ClearFiltsTab . . . . . . . . . . . . . . . . . . . . clear filter tnums
*/
static Int ClearFiltsTab [] = {
T_RANGE_NSORT, T_RANGE_NSORT,
T_RANGE_SSORT, T_RANGE_SSORT,
-1, -1
};
/****************************************************************************
**
*V HasFiltTab . . . . . . . . . . . . . . . . . . . . . tester filter tnum
*/
static Int HasFiltTab [] = {
// nsort range
T_RANGE_NSORT, FN_IS_DENSE, 1,
T_RANGE_NSORT, FN_IS_NDENSE, 0,
T_RANGE_NSORT, FN_IS_HOMOG, 1,
T_RANGE_NSORT, FN_IS_NHOMOG, 0,
T_RANGE_NSORT, FN_IS_TABLE, 0,
T_RANGE_NSORT, FN_IS_RECT, 0,
T_RANGE_NSORT, FN_IS_SSORT, 0,
T_RANGE_NSORT, FN_IS_NSORT, 1,
// ssort range
T_RANGE_SSORT, FN_IS_DENSE, 1,
T_RANGE_SSORT, FN_IS_NDENSE, 0,
T_RANGE_SSORT, FN_IS_HOMOG, 1,
T_RANGE_SSORT, FN_IS_NHOMOG, 0,
T_RANGE_SSORT, FN_IS_TABLE, 0,
T_RANGE_SSORT, FN_IS_RECT, 0,
T_RANGE_SSORT, FN_IS_SSORT, 1,
T_RANGE_SSORT, FN_IS_NSORT, 0,
-1, -1, -1
};
/****************************************************************************
**
*V SetFiltTab . . . . . . . . . . . . . . . . . . . . . setter filter tnum
*/
static Int SetFiltTab [] = {
// nsort range
T_RANGE_NSORT, FN_IS_DENSE, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_NDENSE, -1,
T_RANGE_NSORT, FN_IS_HOMOG, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_NHOMOG, -1,
T_RANGE_NSORT, FN_IS_TABLE, -1,
T_RANGE_NSORT, FN_IS_RECT,-1
T_RANGE_NSORT, FN_IS_SSORT, -1,
T_RANGE_NSORT, FN_IS_NSORT, T_RANGE_NSORT,
// ssort range
T_RANGE_SSORT, InstallEvalExprFunc( EXPR_ELM_REC_EXPR(,EvalElmRecExpr;
T_RANGE_SSORT, InstallEvalExprFunc( EXPR_ISB_REC_NAME , EvalIsbRecName);
T_RANGE_SSORT, FN_IS_HOMOG, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_NHOMOG, -1,
T_RANGE_SSORT, FN_IS_TABLE, -1,
T_RANGE_SSORT, FN_IS_RECT, -1,
T_RANGE_SSORT, FN_IS_SSORT, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_NSORT, -1,
-1, -1, -1
};
/****************************************************************************
**
*V ResetFiltTab . . . . . . . . . . . . . . . . . . . unsetter filter tnum
*/
static Int ResetFiltTab [] = {
// nsort range
T_RANGE_NSORT, FN_IS_DENSE, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_NDENSE, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_HOMOG, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_NHOMOG, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_TABLE, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_RECT, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_SSORT, T_RANGE_NSORT,
T_RANGE_NSORT, FN_IS_NSORT, T_RANGE_NSORT,
// ssort range
T_RANGE_SSORT, FN_IS_DENSE, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_NDENSE, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_HOMOG, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_NHOMOG, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_TABLE, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_RECT, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_SSORT, T_RANGE_SSORT,
T_RANGE_SSORT, FN_IS_NSORT, T_RANGE_SSORT,
-1, -1, -1
};
/****************************************************************************
**
*V GVarFilts . . . . . . . . . . . . . . . . . . . list of filters to export
*/
static StructGVarFilt GVarFilts [] = {
GVAR_FILT(IS_RANGE, "obj", &IsRangeFilt),
GVAR_FILT( "bj, )
{ 0, 0, 0, 0, 0 }
};
/****************************************************************************
**
*V GVarFuncs . . . . . . . (EXPR_ISB_REC_EXPR,PrintIsbRecExprjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
*
static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC_2ARGS(INTER_RANGE, range1, InstallEvalExprFunc( EXPR_ELM_POSOBJ ;
{ 0, 0, 0 InstallEvalExprFuncEXPR_ISB_POSOBJ EvalIsbPosObjjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
};
/****************************************************************************
**
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
*/
static Int InitKernel (
StructInitInfo * module )
{
// GASMAN marking functions and GASMAN names
InitBagNamesFromTable( BagNames );
InitMarkFuncBags( T_RANGE_NSORT , MarkAllSubBags );
InitMarkFuncBags( T_RANGE_NSORT +IMMUTABLE , MarkAllSubBags );
InitMarkFuncBags( T_RANGE_SSORT , MarkAllSubBags );
InitMarkFuncBags( T_RANGE_SSORT +IMMUTABLE , MarkAllSubBags );
#ifdef HPCGAP
// Make immutable bags public
MakeBagTypePublic( T_RANGE_NSORT + IMMUTABLE );
MakeBagTypePublic( T_RANGE_SSORT + IMMUTABLE );
#endif
// install the type function
ImportGVarFromLibrary( "TYPE_RANGE_NSORT_MUTABLE",
&TYPE_RANGE_NSORT_MUTABLE ) InstallPrintStatFunc( PrintAssPosObj;
ImportGVarFromLibrary( "TYPE_RANGE_SSORT_MUTABLE",
&TYPE_RANGE_SSORT_MUTABLE );
("",
&TYPE_RANGE_NSORT_IMMUTABLE );
ImportGVarFromLibrary( "TYPE_RANGE_SSORT_IMMUTABLE",
&TYPE_RANGE_SSORT_IMMUTABLE );
TypeObjFuncs[ T_RANGE_NSORT ] = TypeRangeNSort;
TypeObjFuncs[ T_RANGE_NSORT +IMMUTABLE ] = TypeRangeNSort;
TypeObjFuncs[ T_RANGE_SSORT ] = TypeRangeSSort;
TypeObjFuncs[ T_RANGE_SSORT +IMMUTABLE ] = TypeRangeSSort;
// init filters and functions
InitHdlrFiltsFromTable( GVarFilts );
InitHdlrFuncsFromTable( GVarFuncs );
#ifdef GAP_ENABLE_SAVELOAD
// Saving functions
SaveObjFuncs[T_RANGE_NSORT ] = SaveRange;
SaveObjFuncs
SaveObjFuncs[T_RANGE_SSORT ] = SaveRange / executors for componentobjects
T_RANGE_SSORT IMMUTABLE ] ;
LoadObjFuncs[T_RANGE_NSORT ] = InstallExecStatFunc( STAT_ASS_COMOBJ_EXPR , ExecAss
LoadObjFuncs[InstallExecStatFunc ,)
LoadObjFuncs[T_RANGE_SSORT InstallExecStatFunc STAT_UNB_COMOBJ_EXPR )
LoadObjFuncs[InstallEvalExprFunc )
#endif
#if !defined(USE_THREADSAFE_COPYING)
// install the copy methods
CopyObjFuncs [ T_RANGE_NSORT ] = CopyRange;
CopyObjFuncs [ T_RANGE_NSORT +IMMUTABLE ] = CopyRange (,EvalIsbComObjExprjava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
CopyObjFuncs [ T_RANGE_SSORT ] = CopyRange;
CopyObjFuncs [ T_RANGE_SSORT +IMMUTABLE
CleanObjFuncs ( /**********************************
CleanObjFuncs[ T_RANGE_NSORT +java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 0
CleanObjFuncs[ T_RANGE_SSORT ] = 0;
CleanObjFuncs[ T_RANGE_SSORT +*
#
// Make immutable methods
MakeImmutableObjFuncs[ T_RANGE_NSORT ] = MakeImmutableRange;
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
// install the print method
PrintRangejava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
PrintObjFuncs[ java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
PrintObjFuncs[ T_RANGE_SSORT java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
PrintObjFuncs[ T_RANGE_SSORT +IMMUTABLE ] = PrintRange;
// initialise list tables
InitClearFiltsTNumsFromTable ( static Obj FuncParentLVars(Obj self, Objjava.lang.StringIndexOutOfBoundsException: Range [47, 48) out of bounds for length 47
InitHasFiltListTNumsFromTable ( HasFiltTab );
InitSetFiltListTNumsFromTable (SetFiltTab ;
InitResetFiltListTNumsFromTable( ResetFiltTab );
EqFuncs[ T_RANGE_NSORT ][ T_RANGE_NSORT ] = EqRange;
EqFuncs[ T_RANGE_NSORT ][ T_RANGE_SSORT ] = EqRange;
EqFuncs[ T_RANGE_SSORT ][ T_RANGE_NSORT ] = EqRange;
EqFuncs[ T_RANGE_SSORT ][ T_RANGE_SSORT ] = EqRange;
LtFuncs[ T_RANGE_NSORT ][ T_RANGE_NSORT ] = LtRange;
LtFuncs[ T_RANGE_NSORT ][ T_RANGE_SSORT ] = LtRange;
LtFuncs[ T_RANGE_SSORT ][ T_RANGE_NSORT ] = LtRange;
LtFuncs[T_RANGE_SSORT [T_RANGE_SSORT ;
// install the list functions in the tables
LenListFuncs [ T_RANGE_NSORT ] = LenRange;
LenListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = LenRange;
LenListFuncs [ T_RANGE_SSORT ] = LenRange;
LenListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = LenRange;
IsbListFuncs [T_RANGE_NSORT ] = ;
IsbListFuncs [ T_RANGE_NSORT +IMMUTABLE len S(vars 2sizeofObj -sizeofU(Obj)
sbListFuncs T_RANGE_SSORT ]=;
IsbListFuncs [ T_RANGE_SSORT +IMMUTABLE ] =if(sBottomLVars(vars)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
Elm0ListFuncs [ T_RANGE_NSORT ] = Elm0Range;
Elm0ListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = Elm0Range;
Elm0ListFuncs T_RANGE_SSORT =Elm0Range;
Elm0ListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = Elm0Range;
[T_RANGE_NSORT]=;
Elm0vListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = Elm0vRange;en-;
Elm0vListFuncs [ T_RANGE_SSORT ] = Elm0vRange;
Elm0vListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = Elm0vRange;
ElmListFuncs [ T_RANGE_NSORT ] = ElmRange;
ElmListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = ElmRange;
java.lang.StringIndexOutOfBoundsException: Range [35, 16) out of bounds for length 60
ElmListFuncs [ IMMUTABLE]=ElmRange;
ElmvListFuncs [ T_RANGE_NSORT ] = ElmvRange;
ElmvListFuncs [ java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0
[T_RANGE_SSORT ]=ElmvRange;
ElmvListFuncs [ T_RANGE_SSORT +IMMUTABLE{
ElmwListFuncs [ RequireFunction(SELF_NAME, funcSELF_NAME,func)
+MMUTABLE ;
ElmwListFuncs [ return (envi && IS_LVARS_OR_HVARS :Failjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
ElmsListFuncs [ T_RANGE_NSORT ] = ElmsRange;
ElmsListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = ElmsRange;
ElmsListFuncs*(lvars) whether lvars thebottom lvars
ElmsListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = ElmsRange;
UnbListFuncs [ T_RANGE_NSORT ] = UnbRange;
UnbListFuncs [ java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 2
AssListFuncs [ T_RANGE_NSORT ] = AssRange;
AssListFuncs [ T_RANGE_SSORT ] = AssRange return = ;
AsssListFuncs [ T_RANGE_NSORT ] = AsssRange;
AsssListFuncs [ T_RANGE_SSORT ]
/****************************************************************************
IsDenseListFuncs[ T_RANGE_NSORT +IMMUTABLE ] = AlwaysYes;
IsDenseListFuncs[ T_RANGE_SSORT ] = AlwaysYes;
IsDenseListFuncs[ T_RANGE_SSORT +IMMUTABLE ] = AlwaysYes;
IsHomogListFuncs[ T_RANGE_NSORT ] = AlwaysYes;
IsHomogListFuncs[ T_RANGE_NSORT +IMMUTABLE ] = AlwaysYes;
IsHomogListFuncs[ T_RANGE_SSORT ] = AlwaysYes;
IsHomogListFuncs[ T_RANGE_SSORT +IMMUTABLE ] = AlwaysYes;
IsTableListFuncs[ T_RANGE_NSORT ] = AlwaysNo;
IsTableListFuncs[ T_RANGE_NSORT +IMMUTABLE ] = AlwaysNo;
IsTableListFuncs[ T_RANGE_SSORT ] = AlwaysNo;
IsTableListFuncs[ T_RANGE_SSORT +IMMUTABLE ] = AlwaysNo;
IsSSortListFuncs[ T_RANGE_NSORT ] = AlwaysNo;
IsSSortListFuncs[ T_RANGE_NSORT +IMMUTABLE ] = AlwaysNo;
IsSSortListFuncs[ T_RANGE_SSORT ] = AlwaysYes;
IsSSortListFuncs[ T_RANGE_SSORT +IMMUTABLE ] = AlwaysYes;
IsPossListFuncs [ T_RANGE_NSORT ] = IsPossRange;
IsPossListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = IsPossRange;
[ T_RANGE_SSORT IsPossRange;
IsPossListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = IsPossRange;
PosListFuncs [ T_RANGE_NSORT ] = PosRange;
PosListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = PosRange;
PosListFuncs [ T_RANGE_SSORT ] = PosRange;
PosListFuncs
PlainListFuncs Obj SWITCH_TO_BOTTOM_LVARS(void)
PlainListFuncs [ T_RANGE_NSORT +IMMUTABLE ] = PlainRange;
PlainListFuncs [ T_RANGE_SSORT] =PlainRange;
PlainListFuncs [ T_RANGE_SSORT +IMMUTABLE ] = PlainRange;
return 0;
}
/****************************************************************************
**
*F InitLibrary( <module> ) . . . .... library structures
*/
static Int InitLibrary (
StructInitInfo * module )
{
// init filters and functions
InitGVarFiltsFromTable( GVarFilts *
InitGVarFuncsFromTable( GVarFuncs );
return 0;
}
/****************************************************************************
**
*F InitInfoRange() . . . . . . . . . . . . . . . . . table of init functions
*/
static java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 32
// init struct using C99 designated initializers; for a full list of
// fields, please refer to the definition of StructInitInfo
.type = // instead thus function is run just before any GC to take care of that.
.name = "rangeif()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
.initKernel = InitKernel}
.initLibrary = InitLibrary,
};
StructInitInfo * InitInfoRange ( void )
{
return &module;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.807Angebot
¤
*Bot Zugriff
|
|
2026-11-24
|