/// <summary>Store an object for future lookup.</summary> /// <remarks> /// Store an object for future lookup. /// <p> /// Stores /// <code>newValue</code> /// , but only if there is not already an object for /// the same object name. Callers can tell if the value is new by checking /// the return value with reference equality: /// <pre> /// V obj = ...; /// boolean wasNew = map.addIfAbsent(obj) == obj; /// </pre> /// </remarks> /// <param name="newValue">the object to store.</param> /// <returns> /// /// <code>newValue</code> /// if stored, or the prior value already stored and /// that would have been returned had the caller used /// <code>get(newValue)</code> /// first. /// </returns> /// <?></?> public virtual V AddIfAbsent <Q>(Q newValue) where Q : V { int msk = mask; int i = ((ObjectId)newValue).w1 & msk; V[] tbl = table; V obj; while ((obj = tbl[i]) != null) { if (AnyObjectId.Equals(obj, newValue)) { return(obj); } i = (i + 1) & msk; } if (++size == grow) { Grow(); Insert(newValue); } else { tbl[i] = newValue; } return(newValue); }
/// <exception cref="System.IO.IOException"></exception> private RefUpdate.Result UpdateImpl(RevWalk walk, RefUpdate.Store store) { RevObject newObj; RevObject oldObj; if (GetRefDatabase().IsNameConflicting(GetName())) { return(RefUpdate.Result.LOCK_FAILURE); } try { if (!TryLock(true)) { return(RefUpdate.Result.LOCK_FAILURE); } if (expValue != null) { ObjectId o; o = oldValue != null ? oldValue : ObjectId.ZeroId; if (!AnyObjectId.Equals(expValue, o)) { return(RefUpdate.Result.LOCK_FAILURE); } } if (oldValue == null) { return(store.Execute(RefUpdate.Result.NEW)); } newObj = SafeParse(walk, newValue); oldObj = SafeParse(walk, oldValue); if (newObj == oldObj && !detachingSymbolicRef) { return(store.Execute(RefUpdate.Result.NO_CHANGE)); } if (newObj is RevCommit && oldObj is RevCommit) { if (walk.IsMergedInto((RevCommit)oldObj, (RevCommit)newObj)) { return(store.Execute(RefUpdate.Result.FAST_FORWARD)); } } if (IsForceUpdate()) { return(store.Execute(RefUpdate.Result.FORCED)); } return(RefUpdate.Result.REJECTED); } finally { Unlock(); } }
/// <summary>Lookup an existing mapping.</summary> /// <remarks>Lookup an existing mapping.</remarks> /// <param name="toFind">the object identifier to find.</param> /// <returns>the instance mapped to toFind, or null if no mapping exists.</returns> public virtual V Get(AnyObjectId toFind) { int msk = mask; int i = toFind.w1 & msk; V[] tbl = table; V obj; while ((obj = tbl[i]) != null) { if (AnyObjectId.Equals(obj, toFind)) { return(obj); } i = (i + 1) & msk; } return(null); }
/// <summary>Lookup an existing mapping.</summary> /// <remarks>Lookup an existing mapping.</remarks> /// <param name="toFind">the object identifier to find.</param> /// <returns>the instance mapped to toFind, or null if no mapping exists.</returns> public virtual V Get(AnyObjectId toFind) { int i = toFind.w1 & mask; V[] tbl = table; int end = tbl.Length; V obj; while ((obj = tbl[i]) != null) { if (AnyObjectId.Equals(obj, toFind)) { return(obj); } if (++i == end) { i = 0; } } return(null); }