Esempio n. 1
0
SASStringBTreeEnum_t
SASStringBTreeEnumCreateStartAt (SASStringBTree_t tree, char *start_key)
{
    __SBEnumeration *stringenum = NULL;
    char *maxkey;
    size_t startkey_len = strlen (start_key) + 1;

    stringenum =
        (__SBEnumeration *) malloc (sizeof (__SBEnumeration) + startkey_len);
    if (stringenum != NULL)
    {
        SASLock (tree, SasUserLock__WRITE);
        maxkey = SASStringBTreeGetMaxKey (tree);
        if ((maxkey != NULL) && (strcmp (start_key, maxkey) < 0))
        {
            stringenum->curmod = SASStringBTreeGetModCount (tree);
            stringenum->curcount = SASStringBTreeGetCurCount (tree);
            if (stringenum->curmod != 0L)
            {
                stringenum->hasmore = (strcmp (start_key, maxkey) < 0);
                stringenum->tree = tree;
                stringenum->ref.node = NULL;
                stringenum->ref.pos = 0;
                memcpy ((char *) &stringenum->entryString[0],
                        start_key, startkey_len);
                if (stringenum->entryString[0] != '\0')
                    stringenum->entryString[startkey_len - 2] -= 1;
                stringenum->curkey = &stringenum->entryString[0];
            }
            else
            {
                free (stringenum);
                stringenum = NULL;
            }
        }
        else
        {
            free (stringenum);
            stringenum = NULL;
        }
        SASUnlock (tree);
    }

    return (SASStringBTreeEnum_t) stringenum;
}
Esempio n. 2
0
static int
sassim_btree_test1 ()
{
  SASStringBTree_t stringBTree;
  SASStringBTreeEnum_t senum;
  unsigned long blockSize = block__Size64K;
  char *temp1, *temp2, *temp3, *temp4, *temp5, *temp6;
  char str[64];
  char str2[4] = " ";
  char *strptr;
  char chr;
  int rc1;
  long modcnt;

  stringBTree = SASStringBTreeCreate (blockSize);
  if (!stringBTree)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeCreate(%u)", blockSize);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeCreate (%lu) success", blockSize);
  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu",
		    SASStringBTreeFreeSpace (stringBTree));
  SASSIM_DUMP_BLOCK (stringBTree, 128);
  SASSIM_PRINT_MSG ("SASStringBTreeIsEmpty(stringBTree) = %d",
		    SASStringBTreeIsEmpty (stringBTree));
  rc1 = SASStringBTreePut (stringBTree, (char *) "s", (void *) "s");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree, "s",
			"s");
      return 1;
    }
  rc1 = SASStringBTreePut (stringBTree, (char *) "j", (void *) "j");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree, "j",
			"j");
      return 1;
    }
  rc1 = SASStringBTreePut (stringBTree, (char *) "m", (void *) "m");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree, "m",
			"m");
      return 1;
    }
  rc1 = SASStringBTreePut (stringBTree, (char *) "~", (void *) "~");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree, "~",
			"~");
      return 1;
    }
  rc1 = SASStringBTreePut (stringBTree, (char *) "!", (void *) "!");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree, "!",
			"!");
      return 1;
    }
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  SASSIM_PRINT_MSG ("SASStringBTreeIsEmpty(stringBTree) = %d",
		    SASStringBTreeIsEmpty (stringBTree));
  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (!temp1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey(%p)", stringBTree);
      return 1;
    } else {
      SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=%s", temp1);
      if (strcmp(temp1, "!") != 0)
      {
          SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey(%p) expected <%s> was %s@%p",
        		  stringBTree, "!", temp1, temp1);
      }
    }


  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (!temp2)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMaxKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=%s", temp2);
  rc1 = SASStringBTreeContainsKey (stringBTree, (char *) "s");
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeContainsKey(%p, %s): %d", stringBTree,
			"s", rc1);
      return 1;
    }
  rc1 = SASStringBTreeContainsKey (stringBTree, (char *) "S");
  if (rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeContainsKey(%p, %s): %d", stringBTree,
			"S", rc1);
      return 1;
    }
  temp3 = (char *) SASStringBTreeGet (stringBTree, (char *) "s");
  if (!temp3)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGet(%p, %s): %p", stringBTree, "s",
			temp3);
      return 1;
    }
  temp4 = (char *) SASStringBTreeGet (stringBTree, (char *) "S");
  if (temp4)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGet(%p, %s): %p", stringBTree, "S",
			temp4);
      return 1;
    }
  rc1 = SASStringBTreePut (stringBTree, (char *) "m", (void *) "M");
  if (rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s): %d", stringBTree,
			"m", "M", rc1);
      return 1;
    }
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 =
    (char *) SASStringBTreeReplace (stringBTree, (char *) "m", (void *) "M");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeReplace(%p, %s, %s)", stringBTree,
			"m", "M");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeReplace(m, M) = <%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 =
    (char *) SASStringBTreeReplace (stringBTree, (char *) "n", (void *) "N");
  if (temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeReplace(%p, %s, %s): %p", stringBTree,
			"n", "N", temp5);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeReplace(n,N)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 = (char *) SASStringBTreeRemove (stringBTree, (char *) "s");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeRemove(%p, %s)", stringBTree, "s");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeRemove(s)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 = (char *) SASStringBTreeRemove (stringBTree, (char *) "j");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeRemove(%p, %s)", stringBTree, "j");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeRemove(j)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 = (char *) SASStringBTreeRemove (stringBTree, (char *) "m");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeRemove(%p, %s)", stringBTree, "m");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeRemove(m)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 = (char *) SASStringBTreeRemove (stringBTree, (char *) "~");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeRemove(%p, %s)", stringBTree, "~");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeRemove(~)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp5 = (char *) SASStringBTreeRemove (stringBTree, (char *) "!");
  if (!temp5)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeRemove(%p, %s)", stringBTree, "!");
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeRemove(!)=<%s>", temp5);
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);
  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (temp1)
    {
      SASSIM_PRINT_ERR
	("SASStringBTreeGetMinKey(%p) returned on a empty btree",
	 stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=%s", temp1);
  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (temp2)
    {
      SASSIM_PRINT_ERR
	("SASStringBTreeGetMaxKey(%p) returned on a empty btree",
	 stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=%s", temp2);
  memset (str, '\0', 64);
  strptr = &str[33];
  for (chr = 'a'; chr <= 'z'; chr++)
    {
      *strptr = chr;
      rc1 = SASStringBTreePut (stringBTree, strptr, strptr);
      if (!rc1)
	{
	  SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree,
			    strptr, strptr);
	  return 1;
	}
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
      strptr++;
    }
  modcnt = SASStringBTreeGetModCount (stringBTree);
  if (!modcnt)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetModCount(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetModCount=%ld", modcnt);
  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (!temp1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=%s", temp1);
  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (!temp2)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMaxKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=%s", temp2);
  senum = SASStringBTreeEnumCreate (stringBTree);
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreate(%p)", stringBTree);
      return 1;
    }
  printf ("SASStringBTreeEnumCreate(%p)", stringBTree);
  printf (" SASStringBTreeEnumNext(%p)   =<", senum);
  while (SASStringBTreeEnumHasMore (senum))
    {
      char *temp = (char *) SASStringBTreeEnumNext (senum);
      if (!temp)
	{
	  break;
	}
      SASSIM_PRINT_MSG ("%c", *temp);
    }
  printf (">");
  SASStringBTreeEnumDestroy (senum);
  senum = SASStringBTreeEnumCreate (stringBTree);
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreate(%p)", stringBTree);
      return 1;
    }
  printf ("SASStringBTreeEnumCreate(%p)", stringBTree);
  strptr = &str[1];
  for (chr = 'A'; chr <= 'Z'; chr++)
    {
      *strptr = chr;
      rc1 = SASStringBTreePut (stringBTree, strptr, strptr);
      if (!rc1)
	{
	  SASSIM_PRINT_ERR ("SASStringBTreePut(%p, %s, %s)", stringBTree,
			    strptr, strptr);
	  return 1;
	}
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
      if (SASStringBTreeEnumHasMore (senum))
	{
	  char *temp = (char *) SASStringBTreeEnumNext (senum);
	  if (!temp)
	    {
	      SASSIM_PRINT_ERR ("SASStringBTreeEnumNext(%p)", senum);
	      return 1;
	    }
	  SASSIM_PRINT_MSG ("SASStringBTreeEnumNext(%p)=%c", senum, *temp);
	  strptr++;
	}
      printf (" SASStringBTreeEnumNext(%p)   =<", senum);
      while (SASStringBTreeEnumHasMore (senum))
	{
	  char *temp = (char *) SASStringBTreeEnumNext (senum);
	  if (!temp)
	    {
	      break;
	    }
	  SASSIM_PRINT_MSG ("%c", *temp);
	}
      printf (">");
    }
  SASStringBTreeEnumDestroy (senum);
  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu",
		    SASStringBTreeFreeSpace (stringBTree));
  modcnt = SASStringBTreeGetModCount (stringBTree);
  if (!modcnt)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetModCount(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetModCount=%ld", modcnt);
  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (!temp1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=%s", temp1);
  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (!temp2)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMaxKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=%s", temp2);
  senum = SASStringBTreeEnumCreate (stringBTree);
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreate(%p)", stringBTree);
      return 1;
    }
  printf ("SASStringBTreeEnumCreate(%p)", stringBTree);
  printf (" SASStringBTreeEnumNext(%p)   =<", senum);
  while (SASStringBTreeEnumHasMore (senum))
    {
      char *temp = (char *) SASStringBTreeEnumNext (senum);
      if (!temp)
	{
	  break;
	}
      SASSIM_PRINT_MSG ("%c", *temp);
    }
  printf (">");
  SASStringBTreeEnumDestroy (senum);
  senum = SASStringBTreeEnumCreateStartAt (stringBTree, (char*)"m");
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreateStartAt(%p)", stringBTree);
      return 1;
    }
  printf ("SASStringBTreeEnumCreate(%p)", stringBTree);
  temp6 = SASStringBTreeEnumCurrent(senum);
  printf (" SASStringBTreeEnumNext(%p) %c  =<", senum, *temp6);
  while (SASStringBTreeEnumHasMore (senum))
    {
      char *temp = (char *) SASStringBTreeEnumNext (senum);
      if (!temp)
	{
	  break;
	}
      SASSIM_PRINT_MSG ("%c", *temp);
    }
  printf (">");
  SASStringBTreeEnumDestroy (senum);
#if 1
  for (chr = 'a'; chr <= 'z'; chr++)
    {
      str2[0] = chr;
      temp6 = (char *) SASStringBTreeRemove (stringBTree, str2);
      if (!temp6)
	{
	  break;
	}
      SASSIM_PRINT_MSG ("SASStringBTreeRemove(%s)= %c", str2, *temp6);
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
    }
  for (chr = 'A'; chr <= 'Z'; chr++)
    {
      str2[0] = chr;
      temp6 = (char *) SASStringBTreeRemove (stringBTree, str2);
      if (!temp6)
	{
	  break;
	}
      SASSIM_PRINT_MSG ("SASStringBTreeRemove(%s)= %c", str2, *temp6);
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
    }

  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu",
		    SASStringBTreeFreeSpace (stringBTree));
  SASSIM_DUMP_BLOCK (stringBTree, 128);
#endif
  SASStringBTreeDestroy (stringBTree);
  return 0;
}
Esempio n. 3
0
//#define __SASDebugPrint__ 1
static int
sassim_btree_test_split ()
{
  SASStringBTree_t stringBTree;
  unsigned long blockSize = block__Size64K;
  SASStringBTreeEnum_t senum;
  char *rawkey, *keyval, *strptr;
  char *temp1, *temp2;
  int i, rc1;
  long modcnt;
  char chr, str[128], keylist[128];
  char str2[4] = " ";

  stringBTree = SASStringBTreeCreate (blockSize);
  if (!stringBTree)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeCreate(%zu)", blockSize);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeCreate (%lu) success", blockSize);
  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu", SASStringBTreeFreeSpace (stringBTree));
#ifdef __SASDebugPrint__
  SASSIM_DUMP_BLOCK (stringBTree, 128);
#endif
  SASSIM_PRINT_MSG ("SASStringBTreeIsEmpty(stringBTree) = %d", SASStringBTreeIsEmpty (stringBTree));

  memset (str, '\0', 128);
  strptr = &str[0];
  i = 0;
  for (chr = '1'; chr <= 0x7d; chr++)
    {
      keylist[i] = chr;
      *strptr = chr;
      rc1 = SASStringBTreePut (stringBTree, strptr, strptr);
      if (!rc1) {
        SASSIM_PRINT_ERR ("SASStringBTreePut (%p, %s, %s)", stringBTree, strptr, strptr);
        return 1;
      }
#ifdef __SASDebugPrint__
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
#endif
     strptr++;
     i++;
    }
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);

  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (!temp1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=(%s)", temp1);
  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (!temp2)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMaxKey (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=(%s)", temp2);
  modcnt = SASStringBTreeGetModCount (stringBTree);
  if (!modcnt)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetModCount (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetModCount=%ld", modcnt);

  senum = SASStringBTreeEnumCreate (stringBTree);
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreate (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeEnumCreate(%p)", stringBTree);

  i = 0;
  while (SASStringBTreeEnumHasMore (senum))
    {
      char *temp = (char *) SASStringBTreeEnumNext (senum);
      if (!temp)
        {
          break;
        }
        if (keylist[i] != *temp)
        {
            SASSIM_PRINT_ERR ("SASStringBTreeEnumNext: misscompare %c != %c",
                        keylist[i] != *temp);
            return 1;
        }
      SASSIM_PRINT_MSG ("<%p> %c", temp, *temp);
      i++;
    }
  SASStringBTreeEnumDestroy (senum);

  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu", SASStringBTreeFreeSpace (stringBTree));
#ifdef __SASDebugPrint__
  SASSIM_DUMP_BLOCK (stringBTree, 128);
#endif
  for (chr = 0x31; chr <= 0x60; chr++)
    {
      str2[0] = chr;
      keyval = (char *) SASStringBTreeRemove (stringBTree, str2);
      if (!keyval) {
        SASSIM_PRINT_ERR ("SASStringBTreeRemove (%p, %s) = %c", stringBTree, str2, *keyval);
        return 1;
      } else {
        SASSIM_PRINT_MSG ("SASStringBTreeRemove (%p, %s) = %c", stringBTree, str2, *keyval);
      }

#ifdef __SASDebugPrint__
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
#endif
    }
  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);

  temp1 = SASStringBTreeGetMinKey (stringBTree);
  if (!temp1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMinKey (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMinKey=%s", temp1);
  temp2 = SASStringBTreeGetMaxKey (stringBTree);
  if (!temp2)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetMaxKey(%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetMaxKey=%s", temp2);
  modcnt = SASStringBTreeGetModCount (stringBTree);
  if (modcnt == 0)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeGetModCount (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeGetModCount=%ld", modcnt);

  senum = SASStringBTreeEnumCreate (stringBTree);
  if (!senum)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumCreate (%p)", stringBTree);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeEnumCreate(%p)", stringBTree);

  keyval = (char *) SASStringBTreeEnumNext (senum);
  if (!keyval)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeEnumNext (%p)", senum);
      return 1;
    }
  SASSIM_PRINT_MSG ("<%p> %c", keyval, *keyval);
  if (*keyval != 'a')
  {
    SASSIM_PRINT_ERR ("SASStringBTreeEnumNext(%p)=%c expected 'a'",
                senum, *keyval);
    return 1;
  }
  rawkey = keyval;
  while (SASStringBTreeEnumHasMore (senum))
    {
      keyval = (char *) SASStringBTreeEnumNext (senum);
      if (!keyval)
        {
          SASSIM_PRINT_ERR ("SASStringBTreeEnumNext (%p)", senum);
          return 1;
        }
      SASSIM_PRINT_MSG ("<%p> %c", keyval, *keyval);
      if (rawkey < keyval)
          rawkey = keyval;
      else
      {
          SASSIM_PRINT_ERR ("SASStringBTreeEnumNext(%p) ordering %c=%c",
                          senum, rawkey, *keyval);
          return 1;
      }
    }
  SASStringBTreeEnumDestroy (senum);
  for (chr = 0x61; chr <= 0x7d; chr++)
    {
      str2[0] = chr;
      keyval = (char *) SASStringBTreeRemove (stringBTree, str2);
      if (!keyval) {
        SASSIM_PRINT_ERR ("SASStringBTreeRemove (%p, %s) = %c", stringBTree, str2, *keyval);
        return 1;
      } else {
        SASSIM_PRINT_MSG ("SASStringBTreeRemove (%p, %s) = %c", stringBTree, str2, *keyval);
      }
#ifdef __SASDebugPrint__
      SASSIM_PRINT_MSG ("sasbtree_print=");
      sasbtree_print (stringBTree);
#endif
    }

  SASSIM_PRINT_MSG ("sasbtree_print=");
  sasbtree_print (stringBTree);

  rc1 = SASStringBTreeIsEmpty (stringBTree);
  if (!rc1)
    {
      SASSIM_PRINT_ERR ("SASStringBTreeIsEmpty(stringBTree) = %d", rc1);
      return 1;
    }
  SASSIM_PRINT_MSG ("SASStringBTreeIsEmpty(stringBTree) = %d", rc1);

  SASSIM_PRINT_MSG ("SASStringBTreeFreeSpace() = %zu", SASStringBTreeFreeSpace (stringBTree));

#ifdef __SASDebugPrint__
  SASSIM_DUMP_BLOCK (stringBTree, 128);
#endif
  SASStringBTreeDestroy (stringBTree);

  return 0;
}
Esempio n. 4
0
void *
SASStringBTreeEnumNext (SASStringBTreeEnum_t sbtenum)
{
    __SBEnumeration *stringenum = (__SBEnumeration *) sbtenum;
    void *result = NULL;
    bool found = false;
    char *maxkey;


    SASLock (stringenum->tree, SasUserLock__WRITE);
    maxkey = SASStringBTreeGetMaxKey (stringenum->tree);
#if __SASDebugPrint__ > 1
    sas_printf ("SASStringBTreeEnumNext; enum->tree=%p maxkey=%s\n",
                stringenum->tree, maxkey);
#endif
    if (maxkey != NULL)
    {
        stringenum->hasmore = (strcmp (stringenum->curkey, maxkey) < 0);
        if (stringenum->hasmore)
        {
            SASStringBTreeNode_t curnode = stringenum->ref.node;
            long treemod = SASStringBTreeGetModCount (stringenum->tree);

            if ((curnode != NULL) && (treemod == stringenum->curmod))
            {
                short curpos = stringenum->ref.pos;
                SASStringBTreeNodeHeader *curSBnode =
                    (SASStringBTreeNodeHeader *) curnode;
                if (curpos < curSBnode->count)
                {
                    if (curSBnode->branch[curpos] == NULL)
                    {
                        curpos++;
                        stringenum->ref.pos = curpos;
                        result = curSBnode->vals[curpos];
                        stringenum->curkey = curSBnode->keys[curpos];
                        stringenum->hasmore =
                            (strcmp (stringenum->curkey, maxkey) < 0);
                        found = true;
                    }
                    else
                    {
                        found =
                            SASStringBTreeNodeSearchGT (curnode,
                                                        stringenum->curkey,
                                                        &stringenum->ref);
                        if (found)
                        {
                            curnode = stringenum->ref.node;
                            curSBnode = (SASStringBTreeNodeHeader *) curnode;
                            curpos = stringenum->ref.pos;
                            result = curSBnode->vals[curpos];
                            stringenum->curkey = curSBnode->keys[curpos];
                            stringenum->curcount -= 1;
                            stringenum->hasmore =
                                (strcmp (stringenum->curkey, maxkey) < 0);
                        }
                    }
                    if (stringenum->hasmore)
                        stringenum->curcount -= 1;
                    else if (found)
                        stringenum->curcount = 1;
                    else
                        stringenum->curcount = 0;
                }
            }
            if (!found)
            {
#if __SASDebugPrint__ > 1
                sas_printf ("SASStringBTreeEnumNext; !found enum->tree=%s\n",
                            stringenum->tree, stringenum->curkey);
#endif
                SASStringBTreeNode_t curnode =
                    SASStringBTreeGetRootNode (stringenum->tree);
                if (stringenum->ref.node == NULL)
                {
                    found =
                        SASStringBTreeNodeSearchGE (curnode, stringenum->curkey,
                                                    &stringenum->ref);
#if __SASDebugPrint__ > 1
                    sas_printf ("SASStringBTreeEnumNext; !found curnode=%p SearchGE=%d\n",
                                curnode, found);
#endif
                } else {
                    found =
                        SASStringBTreeNodeSearchGT (curnode, stringenum->curkey,
                                                    &stringenum->ref);
#if __SASDebugPrint__ > 1
                    sas_printf ("SASStringBTreeEnumNext; !found curnode=%p SearchGT=%d\n",
                                curnode, found);
#endif
                }
                if (found)
                {
                    short curpos = stringenum->ref.pos;
                    SASStringBTreeNodeHeader *curSBnode =
                        (SASStringBTreeNodeHeader *) stringenum->ref.node;
                    result = curSBnode->vals[curpos];
                    stringenum->curkey = curSBnode->keys[curpos];
                    stringenum->curmod = treemod;
                    stringenum->curcount =
                        SASStringBTreeGetCurCount (stringenum->tree);
                    stringenum->hasmore =
                        (strcmp (stringenum->curkey, maxkey) < 0);
#if __SASDebugPrint__ > 1
                    sas_printf ("SASStringBTreeEnumNext; curpos=%hd node=%p result=%p\n",
                                curpos, curSBnode, result);
#endif
                }
                else
                {
                    stringenum->hasmore = false;
                }
            }
        }
#ifdef __SASDebugPrint__
    }
    else
    {
        sas_printf ("SASStringBTreeEnumNext; enum->tree=%p invalid\n",
                    stringenum->tree);
#endif
    }
    SASUnlock (stringenum->tree);
//      sas_printf("{%s,%s,%d}",stringenum->curkey, maxkey, stringenum->hasmore);

    return result;
}