Sha256: 819ed4b24f3798b222f53141c1a1ce47a243d4910f29d08b3ee3a66d6101a0a5

Contents?: true

Size: 1.52 KB

Versions: 29

Compression:

Stored size: 1.52 KB

Contents

#include "tst.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len)
{
  struct node *current_node;
  void *longest_match = NULL;
  int key_index;
  
  assert(key != NULL && "key can't be NULL");
  assert(tst != NULL && "tst can't be NULL");
  
  if(key[0] == 0)
    return NULL;
  
  if(tst->head[(int)key[0]] == NULL)
    return NULL;

  
  if(prefix_len) *prefix_len = 0;
  current_node = tst->head[(int)key[0]];
  key_index = 1;
  
  while (current_node != NULL)
    {
      if(key[key_index] == current_node->value)
	{
	  if(current_node->value == 0) {
	    if(prefix_len) *prefix_len = key_index;
	    return current_node->middle;
	  } else {
	    current_node = current_node->middle;
	    if(current_node && current_node->value == 0) {
	      if(prefix_len) *prefix_len = key_index+1;
	      longest_match = current_node->middle;
	    }

            key_index++;
	    continue;
	  }
	}
      else if( ((current_node->value == 0) && (key[key_index] < 64)) ||
	       ((current_node->value != 0) && (key[key_index] <
					       current_node->value)) )
	{
	  if(current_node->value == 0) {
	    if(prefix_len) *prefix_len = key_index;
	    longest_match = current_node->middle;
	  }
	  current_node = current_node->left;
	  continue;
	}
      else
	{
	  if(current_node->value == 0) {
	    if(prefix_len) *prefix_len = key_index;
	    longest_match = current_node->middle;
	  }
	  current_node = current_node->right;
	  continue;
	}
    }
  
  return longest_match;
}

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
IOWA-1.0.3 ext/Classifier/tst_search.c
IOWA-1.0.2 ext/Classifier/tst_search.c
IOWA-1.0.0 ext/Classifier/tst_search.c
mongrel-0.3.10.1 ext/http11/tst_search.c
mongrel-0.3.1 ext/http11/tst_search.c
mongrel-0.3.11 ext/http11/tst_search.c
mongrel-0.3.10 ext/http11/tst_search.c
mongrel-0.3.12.1 ext/http11/tst_search.c
mongrel-0.3.12.2 ext/http11/tst_search.c
mongrel-0.3.12.3 ext/http11/tst_search.c
mongrel-0.3.13.1 ext/http11/tst_search.c
mongrel-0.3.12.4 ext/http11/tst_search.c
mongrel-0.3.13.2 ext/http11/tst_search.c
mongrel-0.3.12 ext/http11/tst_search.c
mongrel-0.3.13.4 ext/http11/tst_search.c
mongrel-0.3.13 ext/http11/tst_search.c
mongrel-0.3.13.3 ext/http11/tst_search.c
mongrel-0.3.7 ext/http11/tst_search.c
mongrel-0.3.3 ext/http11/tst_search.c
mongrel-0.3.2 ext/http11/tst_search.c