/* Function: Remove (string) * Removes the object with the associated textual name. Returns whether it was present in the set. It does not throw an * exception if it was not. After removal the associated ID will be available for assignment again. */ public bool Remove(string name) { IDObjects.Base obj = objectsByName[name]; if (obj == null) { return(false); } else { if (!sparse) { objectsByID[obj.ID] = null; } else { objectsByID.RemoveAt(BinarySearch(obj.ID)); } objectsByName.Remove(name); usedIDs.Remove(obj.ID); return(true); } }
/* Function: Remove (id) * Removes the object with the associated numeric ID. Returns whether it was present in the set. It does not throw an * exception if it was not. After removal the associated ID will be available for assignment again. */ public bool Remove(int id) { if (!sparse) { IDObjects.Base obj = objectsByID[id]; if (obj == null) { return(false); } else { objectsByID[id] = null; objectsByName.Remove(obj.Name); usedIDs.Remove(id); return(true); } } else // sparse { int position = BinarySearch(id); if (position < 0) { return(false); } else { IDObjects.Base obj = objectsByID[position]; objectsByID.RemoveAt(position); objectsByName.Remove(obj.Name); usedIDs.Remove(id); return(true); } } }