inline void hash_unique_table<H, P, A, K>::insert_range_impl(
        key_type const&, InputIt i, InputIt j)
    {
        node_constructor a(*this);

        if(!this->size_) {
            a.construct(*i);
            this->emplace_empty_impl_with_node(a, 1);
            ++i;
            if(i == j) return;
        }

        do {
            // No side effects in this initial code
            // Note: can't use get_key as '*i' might not be value_type - it could
            // be a pair with first_types as key_type without const or a
            // different second_type.
            key_type const& k = extractor::extract(*i);
            std::size_t hash_value = this->hash_function()(k);
            bucket_ptr bucket = this->bucket_ptr_from_hash(hash_value);
            node_ptr pos = this->find_iterator(bucket, k);

            if (!BOOST_UNORDERED_BORLAND_BOOL(pos)) {
                // Doesn't already exist, add to bucket.
                // Side effects only in this block.

                // Create the node before rehashing in case it throws an
                // exception (need strong safety in such a case).
                a.construct(*i);

                // reserve has basic exception safety if the hash function
                // throws, strong otherwise.
                if(this->size_ + 1 >= this->max_load_) {
                    this->reserve_for_insert(this->size_ + insert_size(i, j));
                    bucket = this->bucket_ptr_from_hash(hash_value);
                }

                // Nothing after this point can throw.
                add_node(a, bucket);
            }
        } while(++i != j);
    }
示例#2
0
/* Malloc Function */
void *MyMalloc(int size){
	
	//checking whether given size is lesser than the (array_size - 1000) if okay then proceed, else give an error
	if(size < (ARRAY_SIZE - 1000)){
		
		//void pointers to be used
		void *vir,*adr;
	
		//checking for the HEAD : to find out the initial starting point
		if(!memory[HEAD] && (size+13)<(ARRAY_SIZE - 4)){
			//setting initial starting point
			memory[HEAD]=4;	
			//pointing vir_pointer to the starting address
			vir = &memory[memory[HEAD]];
			//setting the previous point for the block
			insert_pos(HEAD,4);
			memory[4]=0;
			memory[8]=size;
			vir += 8;
			adr = vir;
			memory[12+size] = TRUE;
			insert_pos(17+size,13+size);
			//returning the address
			return adr;					
		}

		/* if HEAD is initialized then check for the next position which HEAD points */
		else{
			int x = memory[HEAD];
			if((isAvailable(x) == TRUE) && (giveSize(x) == size || giveSize(x) > size)){
				void *vir,*adr;
				vir = &memory[x];
				vir += 8;
				adr = vir;
				//setting the chunck is filled
				memory[x+8+size] = TRUE;
				return adr;						
			}
			else{
				int prev = x;
				int next = nextPosition(x);//taking the next position adjacent to 'x'
				//try to find a available slot from the memory
				while(((isAvailable(next) == FALSE) ||  (giveSize(next) < size )) && (next+13+giveSize(next)+size<19996) && giveSize(next) != 0){
					//if not found then go into the loop : set 'prev' to current 'next' and 'next' to next_position of 'next'
					prev = next;
					next = nextPosition(next);
					//check whether new 'next' is available : if available then allocate it, else continue the loop
					if((isAvailable(next) == TRUE) && (giveSize(next)==0)){
						void *vir,*adr;
						insert_pos(prev,next);
						insert_size(size,next+4);
						vir = &memory[next];
						vir += 8;
						adr = vir;
						//setting the chunk is filled
						memory[next+8+size] = TRUE;
						insert_pos(next+size+13,next+size+9);
						return adr;							
					}
					else{
						continue;
					}
				}
				//if available memory slot is found, then allocate it , else give an error 
				if(isAvailable(next) && (next+13+giveSize(next)+size < 19996) && (giveSize(next) == size || giveSize(next) > size || giveSize(next) == 0)){
					
						void *vir,*adr;
						insert_pos(prev,next);
						insert_size(size,next+4);
						vir = &memory[next];
						vir += 8;
						adr = vir;
						//setting the chunk is filled
						memory[next+8+size] = TRUE;
						insert_pos(next+size+13,next+size+9);
						return adr;							
				}
				printf("Cannot allocate space. Memory is filled.\n");
			}			
		}
	

	}

	else{
		printf("The asked Memory Portion cannot be allocated.\n");
	}
	


}