Ejemplo n.º 1
0
/* Original serializer */
int lisp_compare1(DB *dbp, const DBT *a, const DBT *b) {
  int difference;
  double ddifference;
  unsigned char *ad, *bd, at, bt;
  ad = (unsigned char *)a->data;
  bd = (unsigned char *)b->data;

  /* Compare OIDs. */
  difference = read_int(ad, 0) - read_int(bd, 0);
  if (difference) return difference;
  
  /* Have a type tag? */
  if (a->size == 4) 
    if (b->size == 4)
      return 0;
    else
      return -1;
  else if (b->size == 4) 
    return 1;

  at = ad[4]; bt = bd[4];

  /* Compare numerics. */
  if (type_numeric1(at) && type_numeric1(bt)) {
    ddifference = read_num(ad+4) - read_num(bd+4);
    if (ddifference > 0) return 1;
    else if (ddifference < 0) return -1;
    return 0;
  }

  /* Compare types. */
  /* ISE: need extra conditional here...forget why, so research it */
  difference = at - bt;
  if (difference) return difference;

  /* Same type! */
  switch (at) {
  case S1_NIL: /* nil */
    return 0;
  case S_RESERVED:
    return ad[5] < bd[5]; /* different tags */
  case S1_UCS1_SYMBOL: /* 8-bit symbol */
  case S1_UCS1_STRING: /* 8-bit string */
  case S1_UCS1_PATHNAME: /* 8-bit pathname */
    return case_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case S1_UCS2_SYMBOL:  /* 16-bit symbol */
  case S1_UCS2_STRING: /* 16-bit string */
  case S1_UCS2_PATHNAME: /* 16-bit pathname */
    return utf16_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case S1_UCS4_SYMBOL:
  case S1_UCS4_STRING:
  case S1_UCS4_PATHNAME:
    return wcs_cmp((wchar_t*)ad+9, read_int(ad, 5), (wchar_t*)bd+9, read_int(bd, 5)); 
  default:
    return lex_cmp(ad+5, (a->size)-5, bd+5, (b->size)-5);
  }
}
Ejemplo n.º 2
0
/* doc-order comparison */
int nid_cmp(xptr node1, xptr node2) {
	t_nid		nid1;
	t_nid		nid2;
	t_prefix	p1;
	t_prefix	p2;
	int		result=0;

    if (node1 == node2) return result;

	/* load sibling prefixes */
    // !!! Andrey: it seems there is an error. nid_get_nid calls CHECKP but nid_get_prefix doesn't
	nid1 = nid_get_nid(node1);
	nid2 = nid_get_nid(node2);
	p1 = nid_get_prefix(nid1);
	p2 = nid_get_prefix(nid2);

    result = lex_cmp(p1, p2);

	/* nid memory free */
	nid_free(p1.prefix);
	nid_free(p2.prefix);

	return result;
}
Ejemplo n.º 3
0
/* The new base serializer comparison fn */
int lisp_compare2(DB *dbp, 
		  const DBT *a, unsigned char *ad, const unsigned int asize,
		  const DBT *b, unsigned char *bd, const unsigned int bsize) {
  int difference, i;
  int offset;
  double ddifference;
  unsigned char at, bt;
  
  /* Get the 8-bit tag */
  at = ad[0]; bt = bd[0];

  /*******
  printf("Compare value:\n");
  printf(" at=%d bt=%d\n", at, bt);
  printf(" asize=%d bsize=%d\n", asize, bsize);
  for (i=0;i<20;i++) {
    printf(" at[%d]=%d bt[%d]=%d\n", i, ad[i], i, bd[i]);
    } 
  *******/

  /* Compare numerics. */
  if ((type_numeric2(at)) && (type_numeric2(bt))) {
    
    /*    printf("Num1: %f  Num2: %f\n", read_num2(ad), read_num2(bd)); */
    
    ddifference = read_num2(ad) - read_num2(bd);
    if (ddifference > 0) return 1;
    else if (ddifference < 0) return -1;
    return 0;
  }

  /* Compare types. */
  difference = at - bt;
  if (difference) return difference;

  /* Otherwise at == bt, so types are same */

  /* Handle prefix types */
  switch(at) {
  case S2_SYMBOL:
  case S2_PATHNAME:
    /* Make sure the strings are both of the same type */
    difference = ad[1] - bd[1];
    if (difference) return difference;
    at = ad[1];
    offset = 1;
    break;
  default:
    offset = 0;
  }

  
  /*  printf("Prefix type: %d  offset: %d\n", ad[1], offset); */
  

  /* Same type*/
  switch (at) {
  case S2_NIL: /* nil */
    return 0;
  case S_RESERVED:
    return ad[1] < bd[1]; /* different tags */
  case S2_UTF8_STRING: /* 8-bit string */
    /*****
    printf("Doing an 8-bit compare\n");
    *****/
    return case_cmp(ad+5+offset, read_int32(ad+offset, 1), bd+5+offset, read_int32(bd+offset, 1));
  case S2_UTF16_STRING: /* 16-bit string */
    /*****
    printf("Doing a 16-bit compare\n");
    *****/
    return utf16_cmp(ad+5+offset, read_int32(ad+offset, 1), bd+5+offset, read_int32(bd+offset, 1));
  case S2_UTF32_STRING:
    /*****
    printf("Doing a 32-bit compare\n");
    *****/
    return wcs_cmp((wchar_t*)ad+5+offset, read_int32(ad+offset, 1), (wchar_t*)bd+5+offset, read_int32(bd+offset, 1)); 
  default:
    /*****
    printf("Doing a lex compare\n");
    *****/
    return lex_cmp(ad+1+offset, asize-1, bd+1+offset, bsize-1);
  }
}