当前位置: 首页>>代码示例>>C++>>正文


C++ HashMap::compare方法代码示例

本文整理汇总了C++中HashMap::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::compare方法的具体用法?C++ HashMap::compare怎么用?C++ HashMap::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashMap的用法示例。


在下文中一共展示了HashMap::compare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HashMap_Find

/*----------------------------------------------------------------------
 * Find an element of the map.
 * Return the element node or NULL if not found.
  -----------------------------------------------------------------------*/
HashMapNode HashMap_Find(HashMap map, const HashMapKey key)
{
  HashMapKeyNode keynode = HashMap_GetHashMapKeyNode(map, key, FALSE);
  if (keynode)
    {
      HashMapNode node = (HashMapNode)keynode->first;
      while (node)
        {
          if (map->compare(key, node->key) == 0)
            return node;
          node = node->next;
        }
    }
  return NULL;
}
开发者ID:ArcScofield,项目名称:Amaya,代码行数:19,代码来源:containers.c

示例2: HashMap_DestroyElement

/*----------------------------------------------------------------------
 * Destroy an element from the hash map.
 * Both stored element and key are destroyed.
  -----------------------------------------------------------------------*/
void HashMap_DestroyElement(HashMap map, HashMapKey key)
{
  HashMapKeyNode keynode = HashMap_GetHashMapKeyNode(map, key, FALSE);
  if (keynode!=NULL)
  {
    HashMapNode node = (HashMapNode)keynode->first;
    while (node != NULL)
    {
      if (map->compare(key, node->key)==0)
      {
        if (node->key)
          map->destroyKey(node->key);
        DLList_DestroyElement((DLList)keynode, (DLListNode) node);
        return;
      }
      node = node->next;
    }
  }
}
开发者ID:ArcScofield,项目名称:Amaya,代码行数:23,代码来源:containers.c

示例3: HashMap_Remove

/*----------------------------------------------------------------------
 * Remove an element from the hash map and return it.
 * The stored key is destroyed from the map.
  -----------------------------------------------------------------------*/
ContainerElement HashMap_Remove(HashMap map, HashMapKey key)
{
  HashMapKeyNode keynode = HashMap_GetHashMapKeyNode(map, key, FALSE);  
  if (keynode != NULL)
  {
    HashMapNode node = (HashMapNode)keynode->first;
    while (node != NULL)
    {
      if (map->compare(key, node->key)==0)
      {
        if (node->key)
          map->destroyKey(node->key);
        return DLList_RemoveElement((DLList)keynode, (DLListNode) node); 
      }
      node = node->next;
    }
  }
  return NULL;  
}
开发者ID:ArcScofield,项目名称:Amaya,代码行数:23,代码来源:containers.c

示例4: HashMap_Set

/*----------------------------------------------------------------------
 * Set an element in the hash map, the old element is returned.
 * The element and the key are stored in the map.
 * @param key Key of the element.
 * @param elem Element.
 * @return The old element, NULL if none.
  -----------------------------------------------------------------------*/
ContainerElement HashMap_Set(HashMap map, HashMapKey key, ContainerElement elem)
{
  HashMapKeyNode keynode = HashMap_GetHashMapKeyNode(map, key, TRUE);
  HashMapNode node = (HashMapNode)keynode->first;
  ContainerElement old = NULL;
  while (node && map->compare(key, node->key) != 0)
    node = (HashMapNode)node->next;

  if (node)
  {
    old = node->elem;
    node->elem = elem;
    // free the key duplication.
    TtaFreeMemory (key);
  }
  else
  {
    node = (HashMapNode) TtaGetMemory (sizeof(sHashMapNode));
    memset (node, 0, sizeof(sHashMapNode));
    node->elem = elem;
    node->key  = key;
    node->prev = NULL;
    if (keynode->first == NULL)
    {
      keynode->first = keynode->last = (DLListNode)node;
      node->next = NULL;
    }
    else
    {
      keynode->first->prev = (DLListNode)node;
      node->next = (HashMapNode)keynode->first;
      keynode->first = (DLListNode)node; 
    }
  }
  return (ContainerElement)old;
}
开发者ID:ArcScofield,项目名称:Amaya,代码行数:43,代码来源:containers.c


注:本文中的HashMap::compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。