Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/****************************************************************************1**2*W blister.h GAP source Martin Schönert3**4**5*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany6*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland7*Y Copyright (C) 2002 The GAP Group8**9** This file declares the functions that mainly operate on boolean lists.10** Because boolean lists are just a special case of lists many things are11** done in the list package.12**13** A *boolean list* is a list that has no holes and contains only 'true' and14** 'false'. For the full definition of boolean list see chapter "Boolean15** Lists" in the {\GAP} Manual. Read also the section "More about Boolean16** Lists" about the different internal representations of such lists.17*/1819#ifndef GAP_BLISTER_H20#define GAP_BLISTER_H212223/****************************************************************************24**2526*V BIPEB . . . . . . . . . . . . . . . . . . . . . . . . . . bits per block27**28** 'BIPEB' is the number of bits per block, where a block fills a UInt,29** which must be the same size as a bag identifier.30**31*/32#define BIPEB (sizeof(UInt) * 8L)333435/****************************************************************************36**3738*F PLEN_SIZE_BLIST( <size> ) . physical length from size for a boolean list39**40** 'PLEN_SIZE_BLIST' computes the physical length (e.g. the number of41** elements that could be stored in a list) from the <size> (as reported by42** 'SIZE') for a boolean list.43**44** Note that 'PLEN_SIZE_BLIST' is a macro, so do not call it with arguments45** that have side effects.46*/47#define PLEN_SIZE_BLIST(size) \48((((size)-sizeof(Obj))/sizeof(UInt)) * BIPEB)495051/****************************************************************************52**53*F SIZE_PLEN_BLIST( <plen> ) . . size for a blist with given physical length54**55** 'SIZE_PLEN_BLIST' returns the size that a boolean list with room for56** <plen> elements must at least have.57**58** Note that 'SIZE_PLEN_BLIST' is a macro, so do not call it with arguments59** that have side effects.60*/61#define SIZE_PLEN_BLIST(plen) \62(sizeof(Obj)+((plen)+BIPEB-1)/BIPEB*sizeof(UInt))636465/****************************************************************************66**67*F LEN_BLIST( <list> ) . . . . . . . . . . . . . . length of a boolean list68**69** 'LEN_BLIST' returns the logical length of the boolean list <list>, as a C70** integer.71**72** Note that 'LEN_BLIST' is a macro, so do not call it with arguments that73** have side effects.74*/75#define LEN_BLIST(list) (INT_INTOBJ(ADDR_OBJ(list)[0]))767778/***************************************************************************79**80*F NUMBER_BLOCKS_BLIST(<list>) . . . . . . . . number of UInt blocks in list81**82*/83#define NUMBER_BLOCKS_BLIST( blist ) ((LEN_BLIST((blist)) + BIPEB -1)/BIPEB)848586/****************************************************************************87**88*F SET_LEN_BLIST( <list>, <len> ) . . . . set the length of a boolean list89**90** 'SET_LEN_BLIST' sets the length of the boolean list <list> to the value91** <len>, which must be a positive C integer.92**93** Note that 'SET_LEN_BLIST' is a macro, so do not call it with arguments94** that have side effects.95*/96#define SET_LEN_BLIST(list,len) \97(ADDR_OBJ(list)[0] = INTOBJ_INT(len))9899100/****************************************************************************101**102*F BLOCKS_BLIST( <list> ) . . . . . . . . . . first block of a boolean list103**104** returns a pointer to the start of the data of the Boolean list105**106*/107#define BLOCKS_BLIST( list ) ((UInt*)(ADDR_OBJ(list)+1))108109110/****************************************************************************111**112*F BLOCK_ELM_BLIST( <list>, <pos> ) . . . . . . . . block of a boolean list113**114** 'BLOCK_ELM_BLIST' return the block containing the <pos>-th element of the115** boolean list <list> as a UInt value, which is also a valid left hand116** side. <pos> must be a positive integer less than or equal to the length117** of <list>.118**119** Note that 'BLOCK_ELM_BLIST' is a macro, so do not call it with arguments120** that have side effects.121*/122#define BLOCK_ELM_BLIST(list, pos) (BLOCKS_BLIST( list )[((pos)-1)/BIPEB])123124125/****************************************************************************126**127*F MASK_POS_BLIST( <pos> ) . . . . bit mask for position of a Boolean list128**129** MASK_POS_BLIST(<pos>) returns a UInt with a single set bit in position130** (pos-1) % BIPEB, useful for accessing the pos'th element of a blist131**132** Note that 'MASK_POS_BLIST' is a macro, so do not call it with arguments133** that have side effects.134*/135#define MASK_POS_BLIST( pos ) (((UInt) 1)<<((pos)-1)%BIPEB)136137138/****************************************************************************139**140*F ELM_BLIST( <list>, <pos> ) . . . . . . . . . . element of a boolean list141**142** 'ELM_BLIST' return the <pos>-th element of the boolean list <list>, which143** is either 'true' or 'false'. <pos> must be a positive integer less than144** or equal to the length of <list>.145**146** Note that 'ELM_BLIST' is a macro, so do not call it with arguments that147** have side effects.148*/149#define ELM_BLIST(list,pos) \150((BLOCK_ELM_BLIST(list,pos) & MASK_POS_BLIST(pos)) ? True : False)151152153/****************************************************************************154**155*F SET_ELM_BLIST( <list>, <pos>, <val> ) . set an element of a boolean list156**157** 'SET_ELM_BLIST' sets the element at position <pos> in the boolean list158** <list> to the value <val>. <pos> must be a positive integer less than or159** equal to the length of <list>. <val> must be either 'true' or 'false'.160**161** Note that 'SET_ELM_BLIST' is a macro, so do not call it with arguments162** that have side effects.163*/164#define SET_ELM_BLIST(list,pos,val) \165((val) == True ? \166(BLOCK_ELM_BLIST(list, pos) |= MASK_POS_BLIST(pos)) : \167(BLOCK_ELM_BLIST(list, pos) &= ~MASK_POS_BLIST(pos)))168169170/****************************************************************************171**172*F IS_BLIST_REP( <list> ) . . . . . check if <list> is in boolean list rep173*/174#define IS_BLIST_REP(list) \175( T_BLIST <= TNUM_OBJ(list) && TNUM_OBJ(list) <= T_BLIST_SSORT+IMMUTABLE )176177178/****************************************************************************179**180*F COUNT_TRUES_BLOCK( <block> ) . . . . . . . . . . . count number of trues181*/182#ifdef SYS_IS_64_BIT183184#define COUNT_TRUES_BLOCK( block ) \185do { \186(block) = ((block) & 0x5555555555555555L) + (((block) >> 1) & 0x5555555555555555L); \187(block) = ((block) & 0x3333333333333333L) + (((block) >> 2) & 0x3333333333333333L); \188(block) = ((block) + ((block) >> 4)) & 0x0f0f0f0f0f0f0f0fL; \189(block) = ((block) + ((block) >> 8)); \190(block) = ((block) + ((block) >> 16)); \191(block) = ((block) + ((block) >> 32)) & 0x00000000000000ffL; } while (0)192193#else194195#define COUNT_TRUES_BLOCK( block ) \196do { \197(block) = ((block) & 0x55555555) + (((block) >> 1) & 0x55555555); \198(block) = ((block) & 0x33333333) + (((block) >> 2) & 0x33333333); \199(block) = ((block) + ((block) >> 4)) & 0x0f0f0f0f; \200(block) = ((block) + ((block) >> 8)); \201(block) = ((block) + ((block) >> 16)) & 0x000000ff; } while (0)202#endif203204205/****************************************************************************206**207208*F * * * * * * * * * * * * * * list functions * * * * * * * * * * * * * * * *209*/210211/****************************************************************************212**213214215*F AssBlist( <list>, <pos>, <val> ) . . . . . . . assign to a boolean list216**217** 'AssBlist' assigns the value <val> to the boolean list <list> at the218** position <pos>. It is the responsibility of the caller to ensure that219** <pos> is positive, and that <val> is not 0.220**221** 'AssBlist' is the function in 'AssListFuncs' for boolean lists.222**223** If <pos> is less than or equal to the logical length of the boolean list224** and <val> is 'true' or 'false' the assignment is done by setting the225** corresponding bit. If <pos> is one more than the logical length of the226** boolean list the assignment is done by resizing the boolean list if227** necessary, setting the corresponding bit and incrementing the logical228** length by one. Otherwise the boolean list is converted to an ordinary229** list and the assignment is performed the ordinary way.230*/231extern void AssBlist (232Obj list,233Int pos,234Obj val );235236237/****************************************************************************238**239*F ConvBlist( <list> ) . . . . . . . . . convert a list into a boolean list240**241** `ConvBlist' changes the representation of boolean lists into the compact242** representation of type 'T_BLIST' described above.243*/244extern void ConvBlist (245Obj list );246247248/****************************************************************************249**250251*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *252*/253254/****************************************************************************255**256257*F InitInfoBlist() . . . . . . . . . . . . . . . . . table of init functions258*/259StructInitInfo * InitInfoBlist ( void );260261262#endif // GAP_BLISTER_H263264/****************************************************************************265**266267*E blister.h . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here268*/269270271