void AstBasicDType::dump(ostream& str) { this->AstNodeDType::dump(str); str<<" kwd="<<keyword().ascii(); if (isRanged() && !rangep()) str<<" range=["<<msb()<<":"<<lsb()<<"]"; if (implicit()) str<<" [IMPLICIT]"; }
unsigned int RMQ_succinct::query(unsigned int i, unsigned int j) { // i's microblock unsigned int mb_i = microblock(i); // j's microblock unsigned int mb_j = microblock(j); // min: to be returned unsigned int min, min_i, min_j; // start of i's microblock unsigned int s_mi = mb_i * s; // pos. of i in its microblock unsigned int i_pos = i - s_mi; if (mb_i == mb_j) { // only one microblock-query min_i = clearbits(Prec[type[mb_i]][j-s_mi], i_pos); min = min_i == 0 ? j : s_mi + lsb(min_i); } else { // i's block unsigned int b_i = block(i); // j's block unsigned int b_j = block(j); // start of j's microblock unsigned int s_mj = mb_j * s; // position of j in its microblock unsigned int j_pos = j - s_mj; min_i = clearbits(Prec[type[mb_i]][s-1], i_pos); // left in-microblock-query min = min_i == 0 ? s_mi + s - 1 : s_mi + lsb(min_i); min_j = Prec[type[mb_j]][j_pos] == 0 ? // right in-microblock-query j : s_mj + lsb(Prec[type[mb_j]][j_pos]); if (a[min_j] < a[min]) min = min_j; // otherwise we're done! if (mb_j > mb_i + 1) { // start of block i unsigned int s_bi = b_i * sprime; // start of block j unsigned int s_bj = b_j * sprime; // do another microblock-query! if (s_bi+s > i) { mb_i++; // go one microblock to the right min_i = Prec[type[mb_i]][s-1] == 0 ? // right in-block-query s_bi + sprime - 1 : s_mi + s + lsb(Prec[type[mb_i]][s-1]); if (a[min_i] < a[min]) min = min_i; } // and yet another microblock-query! if (j >= s_bj+s) { mb_j--; // go one microblock to the left min_j = Prec[type[mb_j]][s-1] == 0 ? // right in-block-query s_mj - 1 : s_bj + lsb(Prec[type[mb_j]][s-1]); if (a[min_j] < a[min]) min = min_j; } unsigned int block_difference = b_j - b_i; // otherwise we're done! if (block_difference > 1) { // for index calculations in M and M' unsigned int k, twotothek, block_tmp; b_i++; // block where out-of-block-query starts // just one out-of-block-query if (s_bj - s_bi - sprime <= sprimeprime) { k = log2fast(block_difference - 2); // 2^k twotothek = 1 << k; i = m(k, b_i); j = m(k, b_j-twotothek); min_i = a[i] <= a[j] ? i : j; } else { // here we have to answer a superblock-query: // i's superblock unsigned int sb_i = superblock(i); // j's superblock unsigned int sb_j = superblock(j); // end of left out-of-block-query block_tmp = block((sb_i+1)*sprimeprime); k = log2fast(block_tmp - b_i); // 2^k twotothek = 1 << k; i = m(k, b_i); j = m(k, block_tmp+1-twotothek); min_i = a[i] <= a[j] ? i : j; // start of right out-of-block-query block_tmp = block(sb_j*sprimeprime); k = log2fast(b_j - block_tmp); // 2^k twotothek = 1 << k; // going one block to the left doesn't harm and saves some tests block_tmp--; i = m(k, block_tmp); j = m(k, b_j-twotothek); min_j = a[i] <= a[j] ? i : j; if (a[min_j] < a[min_i]) min_i = min_j; // finally, the superblock-query: if (sb_j > sb_i + 1) { k = log2fast(sb_j - sb_i - 2); twotothek = 1 << k; i = Mprime[k][sb_i+1]; j = Mprime[k][sb_j-twotothek]; min_j = a[i] <= a[j] ? i : j; // does NOT always return leftmost min!!! if (a[min_j] < a[min_i]) min_i = min_j; } } // does NOT always return leftmost min!!! if (a[min_i] < a[min]) min = min_i; } } } return min; }
uint32_t SNMPClass::send_message(SNMP_PDU *pdu, IPAddress to_address, uint16_t to_port, byte *temp_buff, char *extra_data) { memset(_packet, 0, SNMP_MAX_PACKET_LEN); _packetPos = SNMP_MAX_PACKET_LEN-1; int32_u u; int t = 0; _extra_data_size = 0; if(extra_data != NULL){ _extra_data_size = strlen(extra_data); } // Varbind List if(pdu->type == SNMP_PDU_RESPONSE){ t = pdu->add_data_private(&pdu->value,_packet + _packetPos,true,temp_buff, _extra_data_size); _packetPos -= t; //length of entire value being passed _packet[_packetPos--] = lsb(t+_extra_data_size); _packet[_packetPos--] = msb(t+_extra_data_size); _packet[_packetPos--] = 0x82;//Sending length in two octets }else if(pdu->type == SNMP_PDU_TRAP2 || pdu->type == SNMP_PDU_INFORM_REQUEST){ //set and increment requestId pdu->requestId = requestCounter++; for (t = pdu->value.size-1; t >= 0; t-- ) { _packet[_packetPos--] = pdu->value.data[t]; } //length of entire value being passed _packet[_packetPos--] = lsb(pdu->value.size); _packet[_packetPos--] = msb(pdu->value.size); _packet[_packetPos--] = 0x82;//Sending length in two octets } _packet[_packetPos--] = (byte)SNMP_SYNTAX_SEQUENCE;// type // Error Index (size always 4 e.g. 4-byte int) u.int32 = pdu->errorIndex; _packet[_packetPos--] = u.data[0]; _packet[_packetPos--] = u.data[1]; _packet[_packetPos--] = u.data[2]; _packet[_packetPos--] = u.data[3]; _packet[_packetPos--] = 0x04; _packet[_packetPos--] = (byte)SNMP_SYNTAX_INT;// type // Error (size always 4 e.g. 4-byte int) u.int32 = pdu->error; _packet[_packetPos--] = u.data[0]; _packet[_packetPos--] = u.data[1]; _packet[_packetPos--] = u.data[2]; _packet[_packetPos--] = u.data[3]; _packet[_packetPos--] = 0x04; _packet[_packetPos--] = (byte)SNMP_SYNTAX_INT;// type // Request ID (size always 4 e.g. 4-byte int) u.int32 = pdu->requestId; _packet[_packetPos--] = u.data[0]; _packet[_packetPos--] = u.data[1]; _packet[_packetPos--] = u.data[2]; _packet[_packetPos--] = u.data[3]; _packet[_packetPos--] = 0x04; _packet[_packetPos--] = (byte)SNMP_SYNTAX_INT;// type //length value of all previous data _packet[_packetPos] = lsb(packet_length()+_extra_data_size); _packet[_packetPos-1] = msb(packet_length()+_extra_data_size); _packetPos -= 2; _packet[_packetPos--] = 0x82;//Sending length in two octets // SNMP PDU type _packet[_packetPos--] = (byte)pdu->type; //data needed for header _dstType = pdu->type; //byte header_size = this->writeHeaders(pdu); this->writeHeaders(pdu); _packetSize = packet_length(); // Serial.println("Outgoing: "); // for(byte i = 0; i < _packetSize; i++){ // Serial.print(_packet[_packetPos+1+i],HEX); // Serial.print("-"); // } // Serial.println(); this->writePacket(to_address, to_port, extra_data); return pdu->requestId; }
int main() { printf("# Random Number Generation & Probability Distributions\n\n"); printf("## Random Number Testing\n\n"); autoseed_old_c_rand(); autoseed_aes(); autoseed_von_neumann(); autoseed_mesrene_twister(); for(int i = 1; i <= MAX_TRIES; i ++) { word32 generated_rand_upper[ARRAY_MAX_SIZE], generated_rand_lower[ARRAY_MAX_SIZE], generated_VN[ARRAY_MAX_SIZE], generated_MT[ARRAY_MAX_SIZE], generated_AES[ARRAY_MAX_SIZE]; printf("### Try %d\n\n", i); printf("#### %d generated numbers\n\n", ARRAY_MAX_SIZE); printf("```\n"); printf(CSV_HEADER); for(int j = 0; j < ARRAY_MAX_SIZE; j ++) { int output_rand = autonext_old_c_rand(); generated_rand_upper[j] = (word32) msb(output_rand); generated_rand_lower[j] = (word32) lsb(output_rand); generated_VN[j] = (word32) autonext_von_neumann(); // Von Neumann generated_MT[j] = (word32) autonext_mesrene_twister(); // Mersenne-Twister generated_AES[j] = (word32) autonext_aes(); // AES printf("%u,", generated_rand_upper[j]); printf("%u,", generated_rand_lower[j]); printf("%u,", generated_VN[j]); printf("%u,", generated_MT[j]); printf("%u\n",generated_AES[j]); } printf("```\n\n"); printf("#### Monobit Frequency Test\n\n"); printf(" - Old C Rand 4 MSBs: %f\n", frequency(ARRAY_MAX_SIZE, 4, generated_rand_upper)); printf(" - Old C Rand 4 LSBs: %f\n", frequency(ARRAY_MAX_SIZE, 4, generated_rand_lower)); printf(" - Von Neumann: %f\n", frequency(ARRAY_MAX_SIZE, 4, generated_VN)); printf(" - Mesrene Twister: %f\n", frequency(ARRAY_MAX_SIZE, 4, generated_MT)); printf(" - AES: %f\n\n", frequency(ARRAY_MAX_SIZE, 4, generated_AES)); printf("#### Runs Length Test\n\n"); printf(" - Old C Rand 4 MSBs: %f\n", run_length(ARRAY_MAX_SIZE, 4, generated_rand_upper)); printf(" - Old C Rand 4 LSBs: %f\n", run_length(ARRAY_MAX_SIZE, 4, generated_rand_lower)); printf(" - Von Neumann: %f\n", run_length(ARRAY_MAX_SIZE, 4, generated_VN)); printf(" - Mesrene Twister: %f\n", run_length(ARRAY_MAX_SIZE, 4, generated_MT)); printf(" - AES: %f\n\n", run_length(ARRAY_MAX_SIZE, 4, generated_AES)); } printf("## M/M/1 queue system\n\n"); run_simulation(12, 20, 180); run_simulation(24, 20, 180); return 0; }