コード例 #1
0
ファイル: IdMap.java プロジェクト: caiograg/grafalgo
 /**
  * Add a new key-id pair.
  *
  * @param key is the key for which an id is required
  * @param id is the requested id that the key is to be mapped to
  * @return the new id or 0 if the key is already mapped or the id is already in use or the
  *     operation fails
  */
 public int addPair(long key, int id) {
   if (validKey(key) || validId(id)) return 0;
   if (!ht.insert(key, id)) return 0;
   ids.swap(id);
   cnt++;
   return id;
 }
コード例 #2
0
ファイル: IdMap.java プロジェクト: caiograg/grafalgo
 /**
  * Add a new key-id pair.
  *
  * @param key is the key for which an id is required
  * @return the new id or 0 if the key is already mapped or the operation fails
  */
 public int addPair(long key) {
   if (validKey(key) || (ids.firstOut() == 0)) return 0;
   int id = ids.firstOut();
   if (!ht.insert(key, id)) return 0;
   ids.swap(id);
   cnt++;
   return id;
 }