_WPRTLINK WCSkipListPtrs * WCSkipNonTempBase::base_insert( TTypePtr elem ) { int k; node_ptr curr; node_ptr found; node_ptr new_node; node_ptr update[ WCSKIPLIST_MAX_PTRS ]; // find where to insert elem found = base_find_with_update( elem, update ); if( !allowDuplicates && found != 0 ) { // duplicates are not allowed for sets and dictionaries base_throw_not_unique(); return( 0 ); } // insert elem after all elements less than elem k = base_random_level(); if( k > level ) { // Make sure the new node has a maximum level more than one than the // current maximum level in the skip list. k = ++level; update[ k ] = header; } // allocate a new node, initailized with elem new_node = base_new_node( elem, k ); if( new_node == 0 ) { base_throw_out_of_memory(); return( 0 ); } // link new_node into the skip list do { curr = update[ k ]; new_node->forward[ k ] = curr->forward[ k ]; curr->forward[ k ] = new_node; } while( --k >= 0 ); num_entries++; return( new_node ); }
_WPRTLINK WCSLink * WCHashBase::base_set_insert( TTypePtr elem ) { unsigned bucket = 0; unsigned index = 0; if( base_find( elem, &bucket, &index, FIND_FIRST ) == 0 ) { if( num_buckets == 0 ) { base_throw_out_of_memory(); return( 0 ); } BaseHashLink * link = WCHashNew( elem ); if( link == 0 ) { base_throw_out_of_memory(); return( 0 ); } hash_array[ bucket ].append( link ); num_entries++; return( link ); } // find succeeded: an equivalent element was previously in the hash set base_throw_not_unique(); return( 0 ); };