//! Reset TDMA slots with given parameters. //! @param[in] slot_count total number of slots. //! @param[in] slot_number slots. //! @param[in] duration slots duration in seconds. void reset(unsigned slot_count, std::vector<unsigned>& slot_number, unsigned duration) { setTotalSlots(slot_count); setSlotNumber(slot_number); setDuration(duration); setup(); }
Page::Page( int localDepth ){ //clean the page memset( content, '0', sizeof( char ) * CAPACITY ); //initial value content[ CAPACITY ] = '\0'; setLocalDepth( localDepth ); setFreeOffset( 4 ); setSlotNumber( 0 ); }
//compress a page, used for split page void Page::adjustPage( ){ int nextFree = 4; int slotSize = getSlotNumber(); int length, offset; int counter = getSlotNumber(); int location = 0; for ( int i = 0; i < slotSize; i ++ ) { length = getRecordLength( i ); //if the length is -1,it means that this data not in this page if ( length == -1 ) counter --; else{ bool flag = 0; //find a slot with record length of -1,if it succeed, then move the data into this slot for (int j = location; j < i; j ++ ) if ( getRecordLength( j ) == -1 ) { location = j; flag = 1; break; } if ( flag == 1 ){ offset = getRecordOffset( i ); memcpy( content + nextFree, content + offset, sizeof( char ) * length ); setRecordOffset( location, nextFree ); setRecordLength( location, length ); setRecordLength( i, -1 ); } nextFree += length; } } //update free offset and slot number setSlotNumber( counter ); setFreeOffset( nextFree ); }
void Page::slotNumberAdd ( ){ setSlotNumber( getSlotNumber() + 1 ); }