Esempio n. 1
0
static void* dttree(Dt_t* dt, void* obj, int type)
{
	Dtlink_t	*root, *t;
	int		cmp, lk, sz, ky;
	void		*o, *k, *key;
	Dtlink_t	*l, *r, *me = NULL, link;
	int		n, minp, turn[DT_MINP];
	Dtcompar_f	cmpf;
	Dtdisc_t*	disc;

	UNFLATTEN(dt);
	disc = dt->disc; _DTDSC(disc,ky,sz,lk,cmpf);
	dt->type &= ~DT_FOUND;

	root = dt->data->here;
	if(!obj)
	{	if(!root || !(type&(DT_CLEAR|DT_FIRST|DT_LAST)) )
			return NIL(void*);

		if(type&DT_CLEAR) /* delete all objects */
		{	if(disc->freef || disc->link < 0)
			{	do
				{	while((t = root->left) )
						RROTATE(root,t);
					t = root->right;
					if(disc->freef)
						(*disc->freef)(dt,_DTOBJ(root,lk),disc);
					if(disc->link < 0)
						(*dt->memoryf)(dt,(void*)root,0,disc);
				} while((root = t) );
			}

			dt->data->size = 0;
			dt->data->here = NIL(Dtlink_t*);
			return NIL(void*);
		}
		else /* computing largest/smallest element */
		{	if(type&DT_LAST)
			{	while((t = root->right) )
					LROTATE(root,t);
			}
			else /* type&DT_FIRST */
			{	while((t = root->left) )
					RROTATE(root,t);
			}

			dt->data->here = root;
			return _DTOBJ(root,lk);
		}
	}
Esempio n. 2
0
ICACHE_FLASH_ATTR void md5_consume(Md5State *state, const uint8_t *chunk) {
    int i;
    uint32_t m[16];
    uint32_t hh[4];
    uint32_t f, g;

    os_bzero(m, sizeof(m));

    for (i=0; i<16; i++)
        m[i] = (chunk[i*4+3]<<24) | (chunk[i*4+2]<<16) |
               (chunk[i*4+1]<<8)  |  chunk[i*4  ];

    for (i=0; i<4; i++)
        hh[i] = state->h[i];

    for (i=0; i<64; i++) {
        if (0 <= i && i <= 15) {
            f = (hh[1] & hh[2]) | (~hh[1] & hh[3]);
            g = i;
        } else if (16 <= i && i <= 31) {
            f = (hh[3] & hh[1]) | (~hh[3] & hh[2]);
            g = (5*i + 1) % 16;
        } else if (32 <= i && i <= 47) {
            f = hh[1] ^ hh[2] ^ hh[3];
            g = (3*i + 5) % 16;
        } else if (48 <= i && i <= 63) {
            f = hh[2] ^ (hh[1] | ~hh[3]);
            g = (7*i) % 16;
        }

        f = f + hh[0] + md5_k[i] + m[g];
        hh[0] = hh[3];
        hh[3] = hh[2];
        hh[2] = hh[1];
        hh[1] = hh[1] + LROTATE(f, md5_s[i]);
    }

    for (i=0; i<4; i++)
        state->h[i] += hh[i];
}
Esempio n. 3
0
/* Demangle incoming sample data from the transfer buffer.
 */
static void read_response(struct acquisition_state *acq)
{
	uint32_t *in_p, *out_p;
	unsigned int words_left, num_words;
	unsigned int max_samples, run_samples;
	unsigned int i;

	words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop)
			- acq->mem_addr_done;
	/* Calculate number of samples to write into packet. */
	max_samples = MIN(acq->samples_max - acq->samples_done,
			  PACKET_SIZE / UNIT_SIZE - acq->out_index);
	run_samples = MIN(max_samples, 2 * words_left);

	/* Round up in case the samples limit is an odd number. */
	num_words = (run_samples + 1) / 2;
	/*
	 * Without RLE the output index will always be a multiple of two
	 * samples (at least before reaching the samples limit), thus 32-bit
	 * alignment is guaranteed.
	 */
	out_p = (uint32_t *)&acq->out_packet[acq->out_index * UNIT_SIZE];
	in_p  = &acq->xfer_buf_in[acq->in_index];
	/*
	 * Transfer two samples at a time, taking care to swap the 16-bit
	 * halves of each input word but keeping the samples themselves in
	 * the original Little Endian order.
	 */
	for (i = 0; i < num_words; i++)
		out_p[i] = LROTATE(in_p[i], 16);

	acq->in_index += num_words;
	acq->mem_addr_done += num_words;
	acq->out_index += run_samples;
	acq->samples_done += run_samples;
}