bool findFab(std::multimap<int,int> pai, pair<int,int> couple)
{
    std::multimap<int,int>::iterator it = pai.end();

    if(pai.size() == 0) return false;

    for ( it = pai.equal_range(couple.first).first; it != pai.equal_range(couple.first).second; ++it)
      if( equals(couple, (*it)) )
          return true;

    return false;
}
bool
MAST::StructuralElementBase::side_external_force(bool request_jacobian,
                                                 DenseRealVector &f,
                                                 DenseRealMatrix &jac,
                                                 std::multimap<libMesh::boundary_id_type, MAST::BoundaryCondition*>& bc) {
    
    // iterate over the boundary ids given in the provided force map
    std::pair<std::multimap<libMesh::boundary_id_type, MAST::BoundaryCondition*>::const_iterator,
    std::multimap<libMesh::boundary_id_type, MAST::BoundaryCondition*>::const_iterator> it;
    
    const libMesh::BoundaryInfo& binfo = *_system.get_mesh().boundary_info;
    
    // for each boundary id, check if any of the sides on the element
    // has the associated boundary
    bool calculate_jac = false;
    
    for (unsigned short int n=0; n<_elem.n_sides(); n++) {
        if (!binfo.n_boundary_ids(&_elem, n))
            continue;
        
        std::vector<libMesh::boundary_id_type> bc_ids = binfo.boundary_ids(&_elem, n);
        std::vector<libMesh::boundary_id_type>::const_iterator bc_it = bc_ids.begin();
        for ( ; bc_it != bc_ids.end(); bc_it++) {
            // find the loads on this boundary and evaluate the f and jac
            it =bc.equal_range(*bc_it);
            
            for ( ; it.first != it.second; it.first++) {
                // apply all the types of loading
                switch (it.first->second->type()) {
                    case MAST::SURFACE_PRESSURE:

                        calculate_jac = (calculate_jac ||
                                         surface_pressure_force(request_jacobian,
                                                                f, jac,
                                                                n,
                                                                *it.first->second));
                        break;
                        
                    case MAST::SMALL_DISTURBANCE_MOTION:
                        calculate_jac = (calculate_jac ||
                                         small_disturbance_surface_pressure_force<ValType>(request_jacobian,
                                                                                           f, jac,
                                                                                           n,
                                                                                           *it.first->second));
                        break;

                    case MAST::DISPLACEMENT_DIRICHLET:
                        // nothing to be done here
                        break;
                        
                    default:
                        // not implemented yet
                        libmesh_error();
                        break;
                }
            }
        }
    }
    return (request_jacobian && calculate_jac);
}
Exemple #3
0
bool World::DeletePersistentData(const PersistentDataItem &item)
{
    int id = item.raw_id();
    if (id > -100)
        return false;
    if (!BuildPersistentCache())
        return false;

    stl::vector<df::historical_figure*> &hfvec = df::historical_figure::get_vector();

    auto eqrange = persistent_index.equal_range(item.key());

    for (auto it2 = eqrange.first; it2 != eqrange.second; )
    {
        auto it = it2; ++it2;

        if (it->second != -id)
            continue;

        persistent_index.erase(it);

        int idx = binsearch_index(hfvec, id);

        if (idx >= 0) {
            delete hfvec[idx];
            hfvec.erase(hfvec.begin()+idx);
        }

        return true;
    }

    return false;
}
Exemple #4
0
void World::GetPersistentData(std::vector<PersistentDataItem> *vec, const std::string &key, bool prefix)
{
    vec->clear();

    if (!BuildPersistentCache())
        return;

    auto eqrange = persistent_index.equal_range(key);

    if (prefix)
    {
        if (key.empty())
        {
            eqrange.first = persistent_index.begin();
            eqrange.second = persistent_index.end();
        }
        else
        {
            std::string bound = key;
            if (bound[bound.size()-1] != '/')
                bound += "/";
            eqrange.first = persistent_index.lower_bound(bound);

            bound[bound.size()-1]++;
            eqrange.second = persistent_index.lower_bound(bound);
        }
    }

    for (auto it = eqrange.first; it != eqrange.second; ++it)
    {
        auto hfig = df::historical_figure::find(-it->second);
        if (hfig && hfig->name.has_name)
            vec->push_back(dataFromHFig(hfig));
    }
}
void CZMQAbstractPublishNotifier::Shutdown()
{
    assert(psocket);

    int count = mapPublishNotifiers.count(address);

    // remove this notifier from the list of publishers using this address
    typedef std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator iterator;
    std::pair<iterator, iterator> iterpair = mapPublishNotifiers.equal_range(address);

    for (iterator it = iterpair.first; it != iterpair.second; ++it)
    {
        if (it->second==this)
        {
            mapPublishNotifiers.erase(it);
            break;
        }
    }

    if (count == 1)
    {
        LogPrint("zmq", "Close socket at address %s\n", address);
        int linger = 0;
        zmq_setsockopt(psocket, ZMQ_LINGER, &linger, sizeof(linger));
        zmq_close(psocket);
    }

    psocket = 0;
}
	int countExampleHandlers(T eventName) {
		int count = 0;
		auto ret = map.equal_range(eventName);
		for(auto it = ret.first;it != ret.second;++it)
			count++;
		return count;
	}
    virtual google::protobuf::Message* GetAddressMappingOperation(
        const pbrpc::Auth& auth,
        const pbrpc::UserCredentials& user_credentials,
        const google::protobuf::Message& request,
        const char* data,
        uint32_t data_len,
        boost::scoped_array<char>* response_data,
        uint32_t* response_data_len) {
      const addressMappingGetRequest* rq
          = reinterpret_cast<const addressMappingGetRequest*>(&request);

      AddressMappingSet* response = new AddressMappingSet();

      pair<multimap<string,AddressMapping>::iterator,
           multimap<string,AddressMapping>::iterator> ret;
      ret = mappings_.equal_range(rq->uuid());
      for (multimap<string,AddressMapping>::iterator it = ret.first;
           it != ret.second;
           ++it) {
        AddressMapping* mapping = response->add_mappings();
        mapping->CopyFrom(it->second);
      }

      return response;
    }
Exemple #8
0
void PatternLink::GenerateConnections( const std::multimap<lem::UCString,const Word_Form*> & points, SynPatternResult * cur_result ) const
{
 typedef std::multimap<lem::UCString,const Word_Form*>::const_iterator IT;
 IT it_from = points.find( from_marker );
 if( it_from==points.end() )
  {
   lem::MemFormatter mem;
   mem.printf( "Can not find node %us.%us to create link head", from_marker.c_str(), from_node.c_str() );
   throw lem::E_BaseException( mem.string() );
  }

 const Word_Form * node0 = it_from->second;

 std::pair<IT,IT> pit = points.equal_range( to_marker );
 if( pit.first==points.end() && !optional_to_node )
  {
   lem::MemFormatter mem;
   mem.printf( "Can not find node %us to create link tail", to_marker.c_str() );
   throw lem::E_BaseException( mem.string() );
  }

 for( IT it=pit.first; it!=pit.second; ++it )
  {
   const Solarix::Word_Form * node1 = it->second;

   PatternLinkEdge new_edge( node0, link_type, node1 );

   cur_result->AddLinkageEdge( new_edge );
  }

 return;
}
Exemple #9
0
	ISoundSource* getSound(const std::string& event)
	{
		auto iterators = events.equal_range(event);
		int dis = std::distance(iterators.first, iterators.second);
		std::advance(iterators.first, rand() % dis);
		return iterators.first->second;
	}
void AMQPAbstractPublishNotifier::Shutdown()
{
    LogPrint("amqp", "amqp: Shutdown notifier %s at %s\n", GetType(), GetAddress());

    int count = mapPublishNotifiers.count(address);

    // remove this notifier from the list of publishers using this address
    typedef std::multimap<std::string, AMQPAbstractPublishNotifier*>::iterator iterator;
    std::pair<iterator, iterator> iterpair = mapPublishNotifiers.equal_range(address);

    for (iterator it = iterpair.first; it != iterpair.second; ++it) {
        if (it->second == this) {
            mapPublishNotifiers.erase(it);
            break;
        }
    }

    // terminate the connection if this is the last publisher using this address
    if (count == 1) {
        handler_->terminate();
        if (thread_.get() != nullptr) {
            if (thread_->joinable()) {
                thread_->join();
            }
        }
    }
}
bool
MAST::HeatConductionElementBase::
volume_external_residual_sensitivity (bool request_jacobian,
                                      RealVectorX& f,
                                      RealMatrixX& jac,
                                      std::multimap<libMesh::subdomain_id_type, MAST::BoundaryConditionBase*>& bc) {
    
    typedef std::multimap<libMesh::subdomain_id_type, MAST::BoundaryConditionBase*> maptype;
    
    // iterate over the boundary ids given in the provided force map
    std::pair<maptype::const_iterator, maptype::const_iterator> it;
    
    // for each boundary id, check if any of the sides on the element
    // has the associated boundary
    bool calculate_jac = false;
    
    libMesh::subdomain_id_type sid = _elem.subdomain_id();
    // find the loads on this boundary and evaluate the f and jac
    it =bc.equal_range(sid);
    
    for ( ; it.first != it.second; it.first++) {
        // apply all the types of loading
        switch (it.first->second->type()) {
                
            case MAST::HEAT_FLUX:
                calculate_jac = (calculate_jac ||
                                 surface_flux_residual_sensitivity(request_jacobian,
                                                                   f, jac,
                                                                   *it.first->second));
                break;
            case MAST::CONVECTION_HEAT_FLUX:
                calculate_jac = (calculate_jac ||
                                 surface_convection_residual_sensitivity(request_jacobian,
                                                                         f, jac,
                                                                         *it.first->second));
                break;
                
            case MAST::SURFACE_RADIATION_HEAT_FLUX:
                calculate_jac = (calculate_jac ||
                                 surface_radiation_residual_sensitivity(request_jacobian,
                                                                        f, jac,
                                                                        *it.first->second));
                break;
                
            case MAST::HEAT_SOURCE:
                calculate_jac = (calculate_jac ||
                                 volume_heat_source_residual_sensitivity(request_jacobian,
                                                                         f, jac,
                                                                         *it.first->second));
                break;
                
            default:
                // not implemented yet
                libmesh_error();
                break;
        }
    }
    
    return (request_jacobian && calculate_jac);
}
    void AudioOutputDeviceManager::removeDeviceEventProc(
        int                                                 _card
        , std::multimap< int, const AudioOutputDevice * > & _devices
    )
    {
        auto    iterators = _devices.equal_range( _card );

        if( iterators.first == _devices.end() ) {
            return;
        }

        DevicesDeleter  deleter(
            _devices
            , iterators
        );

        std::for_each(
            iterators.first
            , iterators.second
            , [
                this
            ]
            (
                std::pair< const int, const AudioOutputDevice * > & _pair
            )
            {
                const auto  DEVICE = _pair.second;

                this->callDisconnectEventHandler(
                    *DEVICE
                );
            }
        );
    }
Exemple #13
0
void updateOperandOrder()
{
  /*Steps:
   * get all routing nodes.
   * for each routing node, get all the outgoing edges
   *  for each outgoing edge, get the operand order from the source of this
   *  routing node to the destination of the edge.
   *  update the operand order map with 
   */

  for(int i=0;i<routingNodes.size();++i)
  {
    int node = routingNodes[i];
    int src = getRouteSrc(node);

    std::pair <std::multimap<int,int>::iterator, std::multimap<int,int>::iterator> ret;
    ret = out_edge.equal_range(node);
    for (std::multimap<int,int>::iterator it=ret.first; it!=ret.second; ++it)
    {
      //edge from route to dest
      std::pair<int,int> edge1(node,it->second);

      //edge from src to dest
      std::pair<int,int> edge2(src,it->second);
      int operandOrder = operand_order_map[edge2];

      operand_order_map.insert(std::pair< std::pair<int,int>,int >(edge1,operandOrder));

    }      

  }
}
Exemple #14
0
void SBTarget::resolveVCProjectDependecies(VCProject* proj, std::multimap<SBTarget*, VCProject*>& vcProjects)
{
  // Get the VCProject's platforms
  StringSet platforms;
  proj->getPlatforms(platforms);
 
  // Iterate over the target's dependencies
  for (auto dep : m_dependencies) {
    // Find all VCProjects generated from the SBTarget
    auto possibleDeps = vcProjects.equal_range(dep);

    // Look for the best-matching VCProject
    // BIG ASSUMPTION: Projects will have distinct platform sets, so only one match exists
    VCProject* match = NULL;
    for (auto it = possibleDeps.first; it != possibleDeps.second; ++it) {
      VCProject* depVCProject = it->second;
      StringSet depPlatforms;
      depVCProject->getPlatforms(depPlatforms);

      if (isSubset(platforms, depPlatforms)) {
        match = depVCProject;
        break;
      }
    }

    sbAssert(match);
    proj->addProjectReference(match);
  }
}
Exemple #15
0
	void ApplyHashMap() {
		UpdateHashToFunctionMap();

		for (auto mf = hashMap.begin(), end = hashMap.end(); mf != end; ++mf) {
			auto range = hashToFunction.equal_range(mf->hash);
			if (range.first == range.second) {
				continue;
			}

			// Yay, found a function.
			for (auto iter = range.first; iter != range.second; ++iter) {
				AnalyzedFunction &f = *iter->second;
				if (f.hash == mf->hash && f.size == mf->size) {
					strncpy(f.name, mf->name, sizeof(mf->name) - 1);

					std::string existingLabel = g_symbolMap->GetLabelString(f.start);
					char defaultLabel[256];
					// If it was renamed, keep it.  Only change the name if it's still the default.
					if (existingLabel.empty() || existingLabel == DefaultFunctionName(defaultLabel, f.start)) {
						g_symbolMap->SetLabelName(mf->name, f.start);
					}
				}
			}
		}
	}
Exemple #16
0
static MDFNCS *FindSetting(const char *name, bool dref_alias, bool dont_freak_out_on_fail)
{
 MDFNCS *ret = NULL;
 uint32 name_hash;

 //printf("Find: %s\n", name);

 name_hash = MakeNameHash(name);

 std::pair<std::multimap <uint32, MDFNCS>::iterator, std::multimap <uint32, MDFNCS>::iterator> sit_pair;
 std::multimap <uint32, MDFNCS>::iterator sit;

 sit_pair = CurrentSettings.equal_range(name_hash);

 for(sit = sit_pair.first; sit != sit_pair.second; sit++)
 {
  //printf("Found: %s\n", sit->second.name);
  if(!strcmp(sit->second.name, name))
  {
   if(dref_alias && sit->second.desc->type == MDFNST_ALIAS)
    return(FindSetting(sit->second.value, dref_alias, dont_freak_out_on_fail));

   ret = &sit->second;
  }
 }

 if(!ret && !dont_freak_out_on_fail)
 {
  printf("\n\nINCONCEIVABLE!  Setting not found: %s\n\n", name);
  exit(1);
 }
 return(ret);
}
void CommandAddRefs::mark_rel_ids(const std::multimap<osmium::object_id_type, osmium::object_id_type>& rel_in_rel, osmium::object_id_type id) {
    auto range = rel_in_rel.equal_range(id);
    for (auto it = range.first; it != range.second; ++it) {
        if (m_relation_ids.count(it->second) == 0) {
            m_relation_ids.insert(it->second);
            mark_rel_ids(rel_in_rel, it->second);
        }
    }
}
Exemple #18
0
void GameDB::deleteGame(std::multimap<Reference<Team>, Reference<Game>>& map, Reference<Team> team, Reference<Game> game) {
  auto range = map.equal_range(team);
  for (auto i = range.first; i != range.second; ++i) {
    if (i->second == game) {
      map.erase(i);
      return;
    }
  }
}
Exemple #19
0
TimingConstraints::mutable_io_constraint_iterator TimingConstraints::find_io_constraint(const NodeId node_id, const DomainId domain_id, std::multimap<NodeId,IoConstraint>& io_constraints) {
    auto range = io_constraints.equal_range(node_id);
    for(auto iter = range.first; iter != range.second; ++iter) {
        if(iter->second.domain == domain_id) return iter;
    }

    //Not found
    return io_constraints.end();
}
 	bool removeExampleHandler (T eventName, Handle handler) {
		auto ret = map.equal_range(eventName);
		for(auto it = ret.first;it != ret.second;++it) {
			if(it->second == handler) {
				it = map.erase(it);
				return true;
			}
		}
		return false;
	}
Exemple #21
0
typename std::multimap<K, V>::iterator
find_pair(std::multimap<K, V>& map, const typename std::multimap<K, V>::value_type& pair)
{
	 typedef typename std::multimap<K, V>::iterator it;
	 std::pair<it,it> range = map.equal_range(pair.first);
	 for (it p = range.first; p != range.second; ++p)
		  if (p->second == pair.second)
				return p;
	 return map.end();
}
Exemple #22
0
void getAverageNormal(
	PackedVertexWithTangents2 & packed,
	std::multimap<PackedVertexWithTangents2,unsigned int> & vertexToOutIndex,
	PackedVertexWithTangents2 & result)
{
	result.position = packed.position;
	result.uv = packed.uv;
	std::multimap<PackedVertexWithTangents2,unsigned int>::iterator it;
	int count = vertexToOutIndex.count(packed);

	for(it = vertexToOutIndex.equal_range(packed).first; it != vertexToOutIndex.equal_range(packed).second; ++it)
	{
		result.normal += it->first.normal;
		result.tangent += it->first.tangent;
		result.biTangent += it->first.biTangent;
	}

	result.normal = glm::normalize(result.normal);
	result.biTangent = glm::normalize(result.biTangent);
	result.tangent = glm::normalize(result.tangent);
}
/// Check if a BuiltinType::Kind matches the MPI datatype.
///
/// \param MultiMap datatype group
/// \param Kind buffer type kind
/// \param MPIDatatype name of the MPI datatype
///
/// \returns true if the pair matches
static bool
isMPITypeMatching(const std::multimap<BuiltinType::Kind, std::string> &MultiMap,
                  const BuiltinType::Kind Kind,
                  const std::string &MPIDatatype) {
  auto ItPair = MultiMap.equal_range(Kind);
  while (ItPair.first != ItPair.second) {
    if (ItPair.first->second == MPIDatatype)
      return true;
    ++ItPair.first;
  }
  return false;
}
// private method for getting a subset of ValidationResult's in a vector
std::vector<sbx::ValidationResult> ValidationResults::_getSubSet(const std::multimap<sbx::productelement_oid, sbx::ValidationResult>& map, sbx::productelement_oid peOid)
{
	std::vector<sbx::ValidationResult> v {};

	const auto& pairs = map.equal_range(peOid); //	std::pair <std::multimap<unsigned short,std::string>::iterator, std::multimap<unsigned short,std::string>::iterator> pairs = _validationResults.equal_range(peOid);

	for ( auto it = pairs.first; it != pairs.second; it++ )
	{
		v.push_back(it->second);
	}

	return v;
}
Exemple #25
0
std::vector<int> getOperands(int nodeID)
{
  std::vector<int> result;
  //we cant have more than 3 operands
  int temp[3];

  int nodeType = getNodeType(nodeID);
  if(nodeType != st_data && nodeType != ld_data)
  {
    std::pair <std::multimap<int,int>::iterator, std::multimap<int,int>::iterator> ret;
    ret = in_edge.equal_range(nodeID);
    int ctr = 0;
    for (std::multimap<int,int>::iterator it=ret.first; it!=ret.second; ++it)
    {
      std::pair<int,int> edge(it->second,nodeID);
      if(operand_order_map.count(edge) > 0)
      {
        temp[operand_order_map[edge]] = it->second;
        ctr++;
      }
    }

    for(int j =0;j<ctr;j++)
      result.push_back(temp[j]);
  }
  else
  {
    std::pair <std::multimap<int,int>::iterator, std::multimap<int,int>::iterator> ret;
    ret = in_edge.equal_range(nodeID);
    for (std::multimap<int,int>::iterator it=ret.first; it!=ret.second; ++it)
    {
        result.push_back(it->second);
    }
  }

  return result;

}
bool
MAST::StructuralElementBase::volume_external_force(bool request_jacobian,
                                                   DenseRealVector &f,
                                                   DenseRealMatrix &jac,
                                                   std::multimap<libMesh::subdomain_id_type, MAST::BoundaryCondition*>& bc) {
    // iterate over the boundary ids given in the provided force map
    std::pair<std::multimap<libMesh::subdomain_id_type, MAST::BoundaryCondition*>::const_iterator,
    std::multimap<libMesh::subdomain_id_type, MAST::BoundaryCondition*>::const_iterator> it;
    
    // for each boundary id, check if any of the sides on the element
    // has the associated boundary
    bool calculate_jac = false;
    
    libMesh::subdomain_id_type sid = _elem.subdomain_id();
    // find the loads on this boundary and evaluate the f and jac
    it =bc.equal_range(sid);
    
    for ( ; it.first != it.second; it.first++) {
        // apply all the types of loading
        switch (it.first->second->type()) {

            case MAST::SURFACE_PRESSURE:
                calculate_jac = (calculate_jac ||
                                 surface_pressure_force(request_jacobian,
                                                        f, jac,
                                                        *it.first->second));
                break;
            case MAST::TEMPERATURE:
                calculate_jac = (calculate_jac ||
                                 thermal_force(request_jacobian,
                                               f, jac,
                                               *it.first->second));
                break;

            case MAST::SMALL_DISTURBANCE_MOTION:
                calculate_jac = (calculate_jac ||
                                 small_disturbance_surface_pressure_force<ValType>(request_jacobian,
                                                                                   f, jac,
                                                                                   *it.first->second));
                break;

            default:
                // not implemented yet
                libmesh_error();
                break;
        }
    }
    
    return (request_jacobian && calculate_jac);
}
/* A chain can extend across multiple atom blocks.  Must segment the chain to fit in an atom 
 * block by identifying the actual atom that forms the root of the new chain.
 * Returns AtomBlockId::INVALID() if this block_index doesn't match up with any chain
 *
 * Assumes that the root of a chain is the primitive that starts the chain or is driven from outside the logic block
 * block_index: index of current atom
 * list_of_pack_pattern: ptr to current chain pattern
 */
static AtomBlockId find_new_root_atom_for_chain(const AtomBlockId blk_id, const t_pack_patterns *list_of_pack_pattern,
        const std::multimap<AtomBlockId,t_pack_molecule*>& atom_molecules) {
    AtomBlockId new_root_blk_id;
	t_pb_graph_pin *root_ipin;
	t_pb_graph_node *root_pb_graph_node;
	t_model_ports *model_port;
	
	VTR_ASSERT(list_of_pack_pattern->is_chain == true);
	root_ipin = list_of_pack_pattern->chain_root_pin;
	root_pb_graph_node = root_ipin->parent_node;

	if(primitive_type_feasible(blk_id, root_pb_graph_node->pb_type) == false) {
		return AtomBlockId::INVALID();
	}

	/* Assign driver furthest up the chain that matches the root node and is unassigned to a molecule as the root */
	model_port = root_ipin->port->model_port;

    AtomPortId port_id = g_atom_nl.find_port(blk_id, model_port);
    if(!port_id) {
        //There is no port with the chain connection on this block, it must be the furthest
        //up the chain, so return it as root
        return blk_id;
    }

	AtomNetId driving_net_id = g_atom_nl.port_net(port_id, root_ipin->pin_number);
	if(!driving_net_id) {
        //There is no net associated with the chain connection on this block, it must be the furthest
        //up the chain, so return it as root
		return blk_id;
	}

    auto driver_pin_id = g_atom_nl.net_driver(driving_net_id);
	AtomBlockId driver_blk_id = g_atom_nl.pin_block(driver_pin_id);

    auto rng = atom_molecules.equal_range(driver_blk_id);
    bool rng_empty = (rng.first == rng.second);
	if(!rng_empty) {
		/* Driver is used/invalid, so current block is the furthest up the chain, return it */
		return blk_id;
	}

	new_root_blk_id = find_new_root_atom_for_chain(driver_blk_id, list_of_pack_pattern, atom_molecules);
	if(!new_root_blk_id) {
		return blk_id;
	} else {
		return new_root_blk_id;
	}
}
	ExampleEventDispatcherTpl() {
		ExampleEventEmitter<T, Rest...>::onExample([&](T eventName, Rest... fargs) {
 			auto ret = map.equal_range(eventName);
 			for(auto it = ret.first;it != ret.second;) {
 				(it->second)(fargs...);
				if(eraseLast) {
					it = map.erase(it);
					eraseLast = false;
				}
				else {
					++it;
				}
 			}
		});
	}
Exemple #29
0
int getMoveForPosition(ChessBoard * board) {

	std::pair<std::multimap<HASHKEY, Coord>::iterator, 
			  std::multimap<HASHKEY, Coord>::iterator> positionStartEnd;

	cerr << board_to_string(board) << endl;
	positionStartEnd = openingBook.equal_range(board->zobristHashKey);

	std::vector<Coord> coords;
	int totalWeight = 0;

	for(std::multimap<HASHKEY, Coord>::iterator itPosition = positionStartEnd.first;
		itPosition != positionStartEnd.second; 
		++itPosition) {
		coords.push_back(itPosition->second);
		totalWeight += itPosition->second.weight;
	}

	// select a move given the weights
	if (coords.empty())
		return -1;

	Coord theCoord;

	if (coords.size() == 1)
		theCoord = coords.front();
	else {
		int whichOne = rand() % totalWeight;
		int weightSoFar = 0;
		for(std::vector<Coord>::iterator itCoords = coords.begin(); itCoords != coords.end(); ++itCoords) {
			if (itCoords->weight + weightSoFar > whichOne) {
				theCoord = *itCoords;
				break;
			}
			weightSoFar += itCoords->weight;
		}

		// convert it to a move
	}
	if (!MoveIsLegal(board, theCoord.move)) {
		cerr << "move from opening book: " << MoveToString(theCoord.move) << " is not legal!" << endl;
		return -1;
	}

	LOG4CPLUS_DEBUG(logger, "book move " << MoveToString(theCoord.move));	
	return theCoord.move;
}
/**
 * @param name A string containing the algorithm name
 * @param version The version to remove. -1 indicates all instances
 * @param typedLoaders A map of names to version numbers
 **/
void FileLoaderRegistryImpl::removeAlgorithm(
    const std::string &name, const int version,
    std::multimap<std::string, int> &typedLoaders) {
  if (version == -1) // remove all
  {
    typedLoaders.erase(name);
  } else // find the right version
  {
    auto range = typedLoaders.equal_range(name);
    for (auto ritr = range.first; ritr != range.second; ++ritr) {
      if (ritr->second == version) {
        typedLoaders.erase(ritr);
        break;
      }
    }
  }
}