コード例 #1
0
ファイル: iterators.cpp プロジェクト: Gamer125/wiibrowser
litehtml::element* litehtml::elements_iterator::next(bool ret_parent)
{
    next_idx();

    while(m_idx < (int) m_el->children().size())
    {
        element* el = m_el->children()[m_idx];
        if(	el->children().size() && m_go_inside && m_go_inside->select(el) )
        {
            stack_item si;
            si.idx		= m_idx;
            si.el		= m_el;
            m_stack.push_back(si);
            m_el		= el;
            m_idx		= -1;
            if(ret_parent)
            {
                return el;
            }
            next_idx();
        } else
        {
            if(!m_select || m_select && m_select->select(m_el->children()[m_idx]))
            {
                return m_el->children()[m_idx];
            } else
            {
                next_idx();
            }
        }
    }

    return 0;
}
コード例 #2
0
ファイル: cyapi.c プロジェクト: HalasNet/bladeRF
/* Assumes a transfer is available and the stream lock is being held */
static int submit_transfer(struct bladerf_stream *stream, void *buffer)
{
    int status = 0;
    PUCHAR xfer;
    struct stream_data *data = get_stream_data(stream);

    LONG buffer_size = (LONG) async_stream_buf_bytes(stream);

    assert(data->transfers[data->avail_i].handle == NULL);
    assert(data->transfers[data->avail_i].buffer == NULL);
    assert(data->num_avail != 0);

    xfer = data->ep->BeginDataXfer((PUCHAR) buffer, buffer_size,
                                   &data->transfers[data->avail_i].event);

    if (xfer != NULL) {
        data->transfers[data->avail_i].handle = xfer;
        data->transfers[data->avail_i].buffer = (PUCHAR) buffer;

        log_verbose("Submitted buffer %p using transfer slot %u.\n",
                    buffer, (unsigned int) data->avail_i);

        data->avail_i = next_idx(data, data->avail_i);
        data->num_avail--;
    } else {
        status = BLADERF_ERR_UNEXPECTED;
        log_debug("Failed to submit buffer %p in transfer slot %u.\n",
                  buffer, (unsigned int) data->avail_i);
    }

    return status;
}
コード例 #3
0
ファイル: ape.cpp プロジェクト: edowson/awb
void 
INST_BUF_CLASS::insert (
    ASIM_INST inst)
{
  ASSERTX(!is_buf_full());
  my_inst[my_tail] = inst;
  my_tail = next_idx(my_tail);
  my_num_entries++;
}
コード例 #4
0
ファイル: ape.cpp プロジェクト: edowson/awb
ASIM_INST 
INST_BUF_CLASS::removeHead()
{
  ASIM_INST inst = my_inst[my_head];
  if (is_buf_empty()) {
    return NULL;
  }
  my_inst[my_head] = NULL;
  my_head = next_idx(my_head);
  my_num_entries--;
  return inst;
}
コード例 #5
0
ファイル: ape.cpp プロジェクト: edowson/awb
void 
INST_BUF_CLASS::free_insts_and_reset()
{
  int i = my_head;
  while (my_inst[i]) {
    my_inst[i] = NULL;
    i = next_idx(i);
  }
  my_head = 0;
  my_tail = 0;
  my_num_entries = 0;
}
コード例 #6
0
uint8 fliflo_buff_get(FLIFLO_QUEUE_t *b) // checked.
{
    uint8 data;
    if ( !b) return 0;
    if ( fliflo_buff_is_empty(b)) return 0;
    if (!b->buffer) return 0;
    data=b->buffer[b->start];
    b->buffer[b->start]=0;              // clobber it to make sure
    b->start=next_idx(b,b->start);

    return data;
}
コード例 #7
0
int fliflo_buff_add(FLIFLO_QUEUE_t *b,uint8 data)  // checked
{
   if (!b->size) return -4;

   if ( !b)                     {DEBUG_LOG(0,"null queue!");        return -2;}
   if (!b->buffer)              {DEBUG_LOG(0,"buffer is missing!"); return -3;}
   if ( fliflo_buff_is_full(b)) {DEBUG_LOG(0,"buffer is full");     return -1;}

   #ifdef DEBUG
    if ((b->end)  > (b->size)) {EXITR(178,0,"ERROR! end:%d pointer>size! %d",b->end,b->size);}
    if ((b->start)> (b->size)) {EXITR(179,0,"ERROR! start:%d pointer>size! %d",b->start,b->size);}
   #endif

   DEBUG_LOG(0,"adding %d to buffer at index:%d",data,b->end);
   b->buffer[b->start]=data;
   b->end=next_idx(b,b->end);
   return 0;
}
コード例 #8
0
ファイル: iov_iter.c プロジェクト: oscardagrach/linux
static size_t copy_page_to_iter_pipe(struct page *page, size_t offset, size_t bytes,
			 struct iov_iter *i)
{
	struct pipe_inode_info *pipe = i->pipe;
	struct pipe_buffer *buf;
	size_t off;
	int idx;

	if (unlikely(bytes > i->count))
		bytes = i->count;

	if (unlikely(!bytes))
		return 0;

	if (!sanity(i))
		return 0;

	off = i->iov_offset;
	idx = i->idx;
	buf = &pipe->bufs[idx];
	if (off) {
		if (offset == off && buf->page == page) {
			/* merge with the last one */
			buf->len += bytes;
			i->iov_offset += bytes;
			goto out;
		}
		idx = next_idx(idx, pipe);
		buf = &pipe->bufs[idx];
	}
	if (idx == pipe->curbuf && pipe->nrbufs)
		return 0;
	pipe->nrbufs++;
	buf->ops = &page_cache_pipe_buf_ops;
	get_page(buf->page = page);
	buf->offset = offset;
	buf->len = bytes;
	i->iov_offset = offset + bytes;
	i->idx = idx;
out:
	i->count -= bytes;
	return bytes;
}
コード例 #9
0
ファイル: cyapi.c プロジェクト: HalasNet/bladeRF
static int cyapi_stream(void *driver, struct bladerf_stream *stream,
                       bladerf_module module)
{
    int status;
    int idx = 0;
    long len;
    void *next_buffer;
    ULONG timeout_ms;
    bool success, done;
    struct stream_data *data = get_stream_data(stream);
    struct bladerf_cyapi *cyapi = get_backend_data(driver);
    struct bladerf_metadata meta;

    assert(stream->dev->transfer_timeout[stream->module] <= ULONG_MAX);
    if (stream->dev->transfer_timeout[stream->module] == 0) {
        timeout_ms = INFINITE;
    } else {
        timeout_ms = stream->dev->transfer_timeout[stream->module];
    }

    switch (module) {
        case BLADERF_MODULE_RX:
            data->ep = get_ep(cyapi->dev, SAMPLE_EP_IN);
            break;

        case BLADERF_MODULE_TX:
            data->ep = get_ep(cyapi->dev, SAMPLE_EP_OUT);
            break;

        default:
            assert(!"Invalid module");
            return BLADERF_ERR_UNEXPECTED;
    }

    if (data->ep == NULL) {
        log_debug("Failed to get EP handle.\n");
        return BLADERF_ERR_UNEXPECTED;
    }

    data->ep->XferMode = XMODE_DIRECT;
    data->ep->Abort();
    data->ep->Reset();

    log_verbose("Starting stream...\n");
    status = 0;
    done = false;
    memset(&meta, 0, sizeof(meta));

    MUTEX_LOCK(&stream->lock);

    for (unsigned int i = 0; i < data->num_transfers && status == 0; i++) {
        if (module == BLADERF_MODULE_TX) {
            next_buffer = stream->cb(stream->dev, stream, &meta, NULL,
                                     stream->samples_per_buffer,
                                     stream->user_data);

            if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
                done = true;
                break;
            } else if (next_buffer == BLADERF_STREAM_NO_DATA) {
                continue;
            }
        } else {
            next_buffer = stream->buffers[i];
        }

        status = submit_transfer(stream, next_buffer);
    }

    MUTEX_UNLOCK(&stream->lock);
    if (status != 0) {
        goto out;
    }

    while (!done) {
        struct transfer *xfer;
        size_t i;

        i = data->inflight_i;
        xfer = &data->transfers[i];
        success = data->ep->WaitForXfer(&xfer->event, timeout_ms);

        if (!success) {
            status = BLADERF_ERR_TIMEOUT;
            log_debug("Steam timed out.\n");
            break;
        }

        len = 0;
        next_buffer = NULL;

        log_verbose("Got transfer complete in slot %u (buffer %p)\n",
                    i, data->transfers[i].buffer);

        MUTEX_LOCK(&stream->lock);
        success = data->ep->FinishDataXfer(data->transfers[i].buffer, len,
                                           &data->transfers[i].event,
                                           xfer->handle);

        if (success) {
            next_buffer = stream->cb(stream->dev, stream, &meta,
                                     data->transfers[i].buffer,
                                     bytes_to_samples(stream->format, len),
                                     stream->user_data);

        } else {
            done = true;
            status = BLADERF_ERR_IO;
            log_debug("Failed to finish transfer %u, buf=%p.\n",
                      (unsigned int)i, &data->transfers[i].buffer);
        }

        data->transfers[i].buffer = NULL;
        data->transfers[i].handle = NULL;
        data->num_avail++;
        pthread_cond_signal(&stream->can_submit_buffer);

        if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
            done = true;
        } else if (next_buffer != BLADERF_STREAM_NO_DATA) {
            status = submit_transfer(stream, next_buffer);
            done = (status != 0);
        }

        data->inflight_i = next_idx(data, data->inflight_i);
        MUTEX_UNLOCK(&stream->lock);
    }

out:

    MUTEX_LOCK(&stream->lock);
    stream->error_code = status;
    stream->state = STREAM_SHUTTING_DOWN;

    data->ep->Abort();
    data->ep->Reset();


    for (unsigned int i = 0; i < data->num_transfers; i++) {
        LONG len = 0;
        if (data->transfers[i].handle != NULL) {
            data->ep->FinishDataXfer(data->transfers[i].buffer, len,
                                     &data->transfers[i].event,
                                     data->transfers[i].handle);


            data->transfers[i].buffer = NULL;
            data->transfers[i].handle = NULL;
            data->num_avail++;
        }
    }

    assert(data->num_avail == data->num_transfers);

    stream->state = STREAM_DONE;
    log_verbose("Stream done (error_code = %d)\n", stream->error_code);
    MUTEX_UNLOCK(&stream->lock);

    return 0;
}
コード例 #10
0
ファイル: MathModule.cpp プロジェクト: Ghor/LoveEngineCore
vector<Triangle> Math::triangulate(const vector<Vertex> &polygon)
{
	if (polygon.size() < 3)
		throw love::Exception("Not a polygon");
	else if (polygon.size() == 3)
		return vector<Triangle>(1, Triangle(polygon[0], polygon[1], polygon[2]));

	// collect list of connections and record leftmost item to check if the polygon
	// has the expected winding
	vector<size_t> next_idx(polygon.size()), prev_idx(polygon.size());
	size_t idx_lm = 0;
	for (size_t i = 0; i < polygon.size(); ++i)
	{
		const Vertex &lm = polygon[idx_lm], &p = polygon[i];
		if (p.x < lm.x || (p.x == lm.x && p.y < lm.y))
			idx_lm = i;
		next_idx[i] = i+1;
		prev_idx[i] = i-1;
	}
	next_idx[next_idx.size()-1] = 0;
	prev_idx[0] = prev_idx.size()-1;

	// check if the polygon has the expected winding and reverse polygon if needed
	if (!is_oriented_ccw(polygon[prev_idx[idx_lm]], polygon[idx_lm], polygon[next_idx[idx_lm]]))
		next_idx.swap(prev_idx);

	// collect list of concave polygons
	list<const Vertex *> concave_vertices;
	for (size_t i = 0; i < polygon.size(); ++i)
	{
		if (!is_oriented_ccw(polygon[prev_idx[i]], polygon[i], polygon[next_idx[i]]))
			concave_vertices.push_back(&polygon[i]);
	}

	// triangulation according to kong
	vector<Triangle> triangles;
	size_t n_vertices = polygon.size();
	size_t current = 1, skipped = 0, next, prev;
	while (n_vertices > 3)
	{
		next = next_idx[current];
		prev = prev_idx[current];
		const Vertex &a = polygon[prev], &b = polygon[current], &c = polygon[next];
		if (is_ear(a,b,c, concave_vertices))
		{
			triangles.push_back(Triangle(a,b,c));
			next_idx[prev] = next;
			prev_idx[next] = prev;
			concave_vertices.remove(&b);
			--n_vertices;
			skipped = 0;
		}
		else if (++skipped > n_vertices)
		{
			throw love::Exception("Cannot triangulate polygon.");
		}
		current = next;
	}
	next = next_idx[current];
	prev = prev_idx[current];
	triangles.push_back(Triangle(polygon[prev], polygon[current], polygon[next]));

	return triangles;
}
コード例 #11
0
ファイル: test_hdrtrie.c プロジェクト: otto-de/varnishevent
static char
*test_HDR_FindIdx(void)
{
#define NODES 10
    struct hdrt_node hdrt[NODES];

    printf("... testing HDR_FindIdx()\n");

    for (int i = 0; i < NODES; i++) {
        hdrt[i].magic = HDRT_NODE_MAGIC;
        hdrt[i].next = calloc(64, sizeof(struct hdrt_node *));
    }

    hdrt[0].str = strdup("FOO");
    hdrt[0].idx = 4711;

    MASSERT(HDR_FindIdx(&hdrt[0], "Foo:") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo: bar") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo:bar") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo: bar baz") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "  Foo  : ") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "  fOO  : ") == 4711);

    MASSERT(HDR_FindIdx(&hdrt[0], "Bar:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "   Bar:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Fo:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Food:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo bar baz") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "   Foo   ") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "      ") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "") == -1);

    hdrt[0].str = strdup("ACCEPT");
    hdrt[0].next[next_idx('-')] = &hdrt[1];

    hdrt[1].str = strdup("");
    hdrt[1].next[next_idx('C')] = &hdrt[2];
    hdrt[1].next[next_idx('E')] = &hdrt[3];
    hdrt[1].next[next_idx('L')] = &hdrt[4];
    hdrt[1].next[next_idx('D')] = &hdrt[5];
    hdrt[1].idx = -1;

    hdrt[2].str = strdup("HARSET");
    hdrt[2].idx = 1;

    hdrt[3].str = strdup("NCODING");
    hdrt[3].idx = 2;

    hdrt[4].str = strdup("ANGUAGE");
    hdrt[4].idx = 3;

    hdrt[5].str = strdup("ATETIME");
    hdrt[5].idx = 4;

    MASSERT(HDR_FindIdx(&hdrt[0], "Accept:") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Charset:") == 1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Encoding:") == 2);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Language:") == 3);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Datetime:") == 4);

    MASSERT(HDR_FindIdx(&hdrt[0], "accept:") == 4711);
    MASSERT(HDR_FindIdx(&hdrt[0], "accept-charset:") == 1);
    MASSERT(HDR_FindIdx(&hdrt[0], "accept-encoding:") == 2);
    MASSERT(HDR_FindIdx(&hdrt[0], "accept-language:") == 3);
    MASSERT(HDR_FindIdx(&hdrt[0], "accept-datetime:") == 4);

    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Foo:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Foo:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-CharsetFoo:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Accept-Charse:") == -1);

    hdrt[0].str = strdup("CONTENT-");
    memset(hdrt[0].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[0].next[next_idx('D')] = &hdrt[1];
    hdrt[0].next[next_idx('E')] = &hdrt[2];
    hdrt[0].next[next_idx('L')] = &hdrt[3];
    hdrt[0].next[next_idx('M')] = &hdrt[4];
    hdrt[0].next[next_idx('R')] = &hdrt[5];
    hdrt[0].next[next_idx('T')] = &hdrt[6];
    hdrt[0].idx = -1;

    hdrt[1].str = strdup("ISPOSITION");
    memset(hdrt[1].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[1].idx = 1;

    hdrt[2].str = strdup("NCODING");
    memset(hdrt[2].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[2].idx = 2;

    hdrt[3].str = strdup("");
    memset(hdrt[3].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[3].next[next_idx('A')] = &hdrt[7];
    hdrt[3].next[next_idx('E')] = &hdrt[8];
    hdrt[3].next[next_idx('O')] = &hdrt[9];
    hdrt[3].idx = -1;

    hdrt[4].str = strdup("D5");
    memset(hdrt[4].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[4].idx = 3;

    hdrt[5].str = strdup("ANGE");
    memset(hdrt[5].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[5].idx = 4;

    hdrt[6].str = strdup("YPE");
    hdrt[6].idx = 5;

    hdrt[7].str = strdup("NGUAGE");
    hdrt[7].idx = 6;

    hdrt[8].str = strdup("NGTH");
    hdrt[8].idx = 7;

    hdrt[9].str = strdup("CATION");
    hdrt[9].idx = 8;

    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Disposition:") == 1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Encoding:") == 2);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Language:") == 6);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Length:") == 7);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Location:") == 8);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-MD5:") == 3);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Range:") == 4);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Type:") == 5);

    MASSERT(HDR_FindIdx(&hdrt[0], "Content-:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-L:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-La:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Le:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Lo:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "Content-Foo:") == -1);

    hdrt[0].str = strdup("X-");
    memset(hdrt[0].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[0].next[next_idx('C')] = &hdrt[1];
    hdrt[0].next[next_idx('F')] = &hdrt[2];
    hdrt[0].idx = -1;

    hdrt[1].str = strdup("SRF-TOKEN");
    memset(hdrt[1].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[1].idx = 1;

    hdrt[2].str = strdup("ORWARDED-");
    memset(hdrt[2].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[2].next[next_idx('F')] = &hdrt[3];
    hdrt[2].next[next_idx('H')] = &hdrt[4];
    hdrt[2].next[next_idx('P')] = &hdrt[5];
    hdrt[2].idx = -1;

    hdrt[3].str = strdup("OR");
    memset(hdrt[3].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[3].idx = 2;

    hdrt[4].str = strdup("OST");
    memset(hdrt[4].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[4].idx = 3;

    hdrt[5].str = strdup("ROTO");
    memset(hdrt[5].next, 0, 64 * sizeof(struct hdrt_node *));
    hdrt[5].idx = 4;

    MASSERT(HDR_FindIdx(&hdrt[0], "X-Csrf-Token:") == 1);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-For:") == 2);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-Host:") == 3);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-Proto:") == 4);

    MASSERT(HDR_FindIdx(&hdrt[0], "X-:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-F:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-H:") == -1);
    MASSERT(HDR_FindIdx(&hdrt[0], "X-Forwarded-P:") == -1);

    return NULL;
}
コード例 #12
0
ファイル: test_hdrtrie.c プロジェクト: otto-de/varnishevent
static char
*test_HDR_InsertIdx(void)
{
#define NODES 10
#define SIZEOF_NEXTTBL (64 * sizeof(struct hdrt_node *))
    struct hdrt_node *hdrt, *hdrt2, *next;

    printf("... testing HDR_InsertIdx()\n");

    next = calloc(64, sizeof(next));
    MAN(next);

    hdrt = HDR_InsertIdx(NULL, "Foo", 4711);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt->str, "FOO") == 0);
    MASSERT(hdrt->idx == 4711);
    MASSERT(memcmp(hdrt->next, next, SIZEOF_NEXTTBL) == 0);
    MASSERT(HDR_FindIdx(hdrt, "Foo:") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "Foo: bar") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "Foo:bar") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "Foo: bar baz") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "  Foo  : ") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "  fOO  : ") == 4711);

    MASSERT(HDR_FindIdx(hdrt, "Bar:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "   Bar:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Fo:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Food:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Foo bar baz") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Foo") == -1);
    MASSERT(HDR_FindIdx(hdrt, "   Foo   ") == -1);
    MASSERT(HDR_FindIdx(hdrt, "      ") == -1);
    MASSERT(HDR_FindIdx(hdrt, "") == -1);

    hdrt = HDR_InsertIdx(hdrt, "Foo", 4711);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    MASSERT(HDR_FindIdx(hdrt, "Foo:") == 4711);

    hdrt = HDR_InsertIdx(hdrt, "Bar", 1147);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    MASSERT(*hdrt->str == '\0');
    MASSERT(hdrt->idx == -1);
    for (int i = 0; i < 64; i ++)
        if (i != next_idx('B') && i != next_idx('F'))
            MAZ(hdrt->next[i]);
    hdrt2 = hdrt->next[next_idx('B')];
    MCHECK_OBJ_NOTNULL(hdrt2, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt2->str, "AR") == 0);
    MASSERT(hdrt2->idx == 1147);
    MASSERT(memcmp(hdrt2->next, next, SIZEOF_NEXTTBL) == 0);
    hdrt2 = hdrt->next[next_idx('F')];
    MCHECK_OBJ_NOTNULL(hdrt2, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt2->str, "OO") == 0);
    MASSERT(hdrt2->idx == 4711);
    MASSERT(memcmp(hdrt2->next, next, SIZEOF_NEXTTBL) == 0);
    MASSERT(HDR_FindIdx(hdrt, "Foo:") == 4711);
    MASSERT(HDR_FindIdx(hdrt, "Bar:") == 1147);

    hdrt = HDR_InsertIdx(NULL, "Accept", 1);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    hdrt = HDR_InsertIdx(hdrt, "Accept-Encoding", 2);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt->str, "ACCEPT") == 0);
    MASSERT(hdrt->idx == 1);
    for (int i = 0; i < 64; i ++)
        if (i != next_idx('-'))
            MAZ(hdrt->next[i]);
    hdrt2 = hdrt->next[next_idx('-')];
    MCHECK_OBJ_NOTNULL(hdrt2, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt2->str, "ENCODING") == 0);
    MASSERT(hdrt2->idx == 2);
    MASSERT(memcmp(hdrt2->next, next, SIZEOF_NEXTTBL) == 0);
    MASSERT(HDR_FindIdx(hdrt, "Accept:") == 1);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Encoding:") == 2);

    hdrt = HDR_InsertIdx(hdrt, "Accept-Charset", 3);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    hdrt = HDR_InsertIdx(hdrt, "Accept-Language", 4);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    hdrt = HDR_InsertIdx(hdrt, "Accept-Datetime", 5);
    MCHECK_OBJ_NOTNULL(hdrt, HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt->str, "ACCEPT") == 0);
    MASSERT(hdrt->idx == 1);
    for (int i = 0; i < 64; i ++)
        if (i != next_idx('-'))
            MAZ(hdrt->next[i]);
    hdrt2 = hdrt->next[next_idx('-')];
    MCHECK_OBJ_NOTNULL(hdrt2, HDRT_NODE_MAGIC);
    MASSERT(*hdrt2->str == '\0');
    MASSERT(hdrt2->idx == -1);
    for (int i = 0; i < 64; i ++)
        if (i != next_idx('C') && i != next_idx('D') && i != next_idx('E')
            && i != next_idx('L'))
            MAZ(hdrt2->next[i]);
    MCHECK_OBJ_NOTNULL(hdrt2->next[next_idx('C')], HDRT_NODE_MAGIC);
    MCHECK_OBJ_NOTNULL(hdrt2->next[next_idx('D')], HDRT_NODE_MAGIC);
    MCHECK_OBJ_NOTNULL(hdrt2->next[next_idx('E')], HDRT_NODE_MAGIC);
    MCHECK_OBJ_NOTNULL(hdrt2->next[next_idx('L')], HDRT_NODE_MAGIC);
    MASSERT(strcmp(hdrt2->next[next_idx('C')]->str, "HARSET") == 0);
    MASSERT(hdrt2->next[next_idx('C')]->idx == 3);
    MASSERT(strcmp(hdrt2->next[next_idx('D')]->str, "ATETIME") == 0);
    MASSERT(hdrt2->next[next_idx('D')]->idx == 5);
    MASSERT(strcmp(hdrt2->next[next_idx('E')]->str, "NCODING") == 0);
    MASSERT(hdrt2->next[next_idx('E')]->idx == 2);
    MASSERT(strcmp(hdrt2->next[next_idx('L')]->str, "ANGUAGE") == 0);
    MASSERT(hdrt2->next[next_idx('L')]->idx == 4);
    MASSERT(HDR_FindIdx(hdrt, "Accept:") == 1);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Charset:") == 3);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Encoding:") == 2);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Language:") == 4);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Datetime:") == 5);

    hdrt = HDR_InsertIdx(NULL, "Accept-Encoding", 4711);
    hdrt = HDR_InsertIdx(hdrt, "Accept", 1147);
    MASSERT(HDR_FindIdx(hdrt, "Accept:") == 1147);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Charset:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Accept-Encoding:") == 4711);

    hdrt = HDR_InsertIdx(NULL, "Content-Disposition", 1);
    hdrt = HDR_InsertIdx(hdrt, "Content-Encoding", 2);
    hdrt = HDR_InsertIdx(hdrt, "Content-Language", 3);
    hdrt = HDR_InsertIdx(hdrt, "Content-Length", 4);
    hdrt = HDR_InsertIdx(hdrt, "Content-Location", 5);
    hdrt = HDR_InsertIdx(hdrt, "Content-MD5", 6);
    hdrt = HDR_InsertIdx(hdrt, "Content-Range", 7);
    hdrt = HDR_InsertIdx(hdrt, "Content-Type", 8);
    MASSERT(HDR_FindIdx(hdrt, "Content-Disposition:") == 1);
    MASSERT(HDR_FindIdx(hdrt, "Content-Encoding:") == 2);
    MASSERT(HDR_FindIdx(hdrt, "Content-Language:") == 3);
    MASSERT(HDR_FindIdx(hdrt, "Content-Length:") == 4);
    MASSERT(HDR_FindIdx(hdrt, "Content-Location:") == 5);
    MASSERT(HDR_FindIdx(hdrt, "Content-MD5:") == 6);
    MASSERT(HDR_FindIdx(hdrt, "Content-Range:") == 7);
    MASSERT(HDR_FindIdx(hdrt, "Content-Type:") == 8);

    MASSERT(HDR_FindIdx(hdrt, "Content-:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content-L:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content-La:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content-Le:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content-Lo:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "Content-Foo:") == -1);

    hdrt = HDR_InsertIdx(NULL, "X-Csrf-Token", 11);
    hdrt = HDR_InsertIdx(hdrt, "X-Forwarded-For", 12);
    hdrt = HDR_InsertIdx(hdrt, "X-Forwarded-Host", 13);
    hdrt = HDR_InsertIdx(hdrt, "X-Forwarded-Proto", 14);

    MASSERT(HDR_FindIdx(hdrt, "X-Csrf-Token:") == 11);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-For:") == 12);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-Host:") == 13);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-Proto:") == 14);

    MASSERT(HDR_FindIdx(hdrt, "X-:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-F:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-H:") == -1);
    MASSERT(HDR_FindIdx(hdrt, "X-Forwarded-P:") == -1);

    hdrt = HDR_InsertIdx(NULL, "Beresp", 0);
    hdrt = HDR_InsertIdx(hdrt, "BerespBody", 1);
    hdrt = HDR_InsertIdx(hdrt, "Bereq", 2);
    MASSERT(HDR_FindIdx(hdrt, "Beresp:") == 0);
    MASSERT(HDR_FindIdx(hdrt, "BerespBody:") == 1);
    MASSERT(HDR_FindIdx(hdrt, "Bereq:") == 2);

    return NULL;
}