Exemple #1
0
/**
 * @brief TEST_CASE - Confirms that duplicate entries are disallowed when the skiplist is a set.
 */
static int duplicate_entries_disallowed( void )
{
	unsigned int i;
	skiplist_node_t *iter;
	skiplist_t *skiplist;

	skiplist = skiplist_create( SKIPLIST_PROPERTY_UNIQUE, 5, int_compare, int_fprintf, NULL );
	if( !skiplist )
		return -1;

	for( i = 0; i < 2; ++i )
	{
		unsigned int j;
		for( j = 0; j < 5; ++j )
		{
			if( skiplist_insert( skiplist, j ) )
				return -1;
			if( skiplist_size( skiplist, NULL ) != (i ? 5 : j+1) )
				return -1;
		}
	}

	for( i = 0; i < 5; ++i )
		if( !skiplist_contains( skiplist, i, NULL ) )
			return -1;

	for( i = 0, iter = skiplist_begin( skiplist ); iter != skiplist_end(); iter = skiplist_next( iter ), ++i )
		if( skiplist_node_value( iter, NULL ) != i )
			return -1;

	if( skiplist_fprintf_filename( "duplicate_entries_disallowed.dot", skiplist ) )
		return -1;

	return 0;
}
Exemple #2
0
void skiplist_debug_levels(SkipList_t *ptrSl, int32_t *rgC, int32_t cSize) {
  assert(cSize == skiplist_size(ptrSl));
  int32_t i = 0;
  SkipListNode_t *ptrSln = ptrSl->ptrSlnHeader->rgPtrSlnForward[0];
  while (i < cSize && ptrSln) {
    rgC[i++] = ptrSln->cLevel;
    ptrSln = ptrSln->rgPtrSlnForward[0];
  }
}
Exemple #3
0
/**
 * @brief TEST_CASE - Sanity test of some key skiplist APIs using integers.
 */
static int simple( void )
{
	unsigned int i;
	skiplist_node_t *iter;
	skiplist_t *skiplist;

	skiplist = skiplist_create( SKIPLIST_PROPERTY_NONE, 5, int_compare, int_fprintf, NULL );
	if( !skiplist )
		return -1;

	if( skiplist_contains( skiplist, 10, NULL ) )
		return -1;

	if( !skiplist_remove( skiplist, 10 ) )
		return -1;

	for( i = 0; i < 10; ++i )
	{
		if( skiplist_insert( skiplist, i ) )
			return -1;
		if( !skiplist_contains( skiplist, i, NULL ) )
			return -1;
	}

	for( i = 0; i < 100; ++i )
	{
		unsigned int value = rand();
		if( skiplist_insert( skiplist, value ) )
			return -1;
		if( !skiplist_contains( skiplist, value, NULL ) )
			return -1;
	}

	for( i = 5; i < 10; ++i )
		if( skiplist_remove( skiplist, i ) )
			return -1;

	for( iter = skiplist_begin( skiplist );
	     iter != skiplist_end();
	     iter = skiplist_next( iter ) )
	{
		uintptr_t value = skiplist_node_value( iter, NULL );
		if( value >= 5 && value < 10 )
			return -1;
	}

	for( i = 0; i < skiplist_size( skiplist, NULL ); ++i )
		skiplist_at_index( skiplist, i, NULL );

	if( skiplist_fprintf_filename( "simple.dot", skiplist ) )
		return -1;

	skiplist_destroy( skiplist );

	return 0;
}
Exemple #4
0
void print_levels(SkipList_t *ptrSl) {
  int cSize = skiplist_size(ptrSl);
  int32_t *rgC = (int32_t*)malloc(sizeof(int32_t)*cSize);
  skiplist_debug_levels(ptrSl,rgC,cSize);
  int32_t i;
  printf("Skiplist Levels: ");
  for (i = 0; i < cSize; i++) {
    printf("%d ", rgC[i]);
  }
  printf("\n");
}
Exemple #5
0
/**
 * @brief TEST_CASE - Confirms incorrect inputs are handled gracefully for skiplist_size.
 */
static int abuse_skiplist_size( void )
{
	if( skiplist_size( NULL, NULL ) )
		return -1;
	return 0;
}