TrackIDPool.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections.Generic;
  2. namespace BBIWARG.Recognition.Tracking
  3. {
  4. /// <summary>
  5. /// Generates unique IDs and keeps track of the currently used IDs.
  6. /// </summary>
  7. public class TrackIDPool
  8. {
  9. /// <summary>
  10. /// the currently used IDs
  11. /// </summary>
  12. private List<int> usedIDs;
  13. /// <summary>
  14. /// Initializes a new instance of the TrackIDPool class.
  15. /// </summary>
  16. public TrackIDPool()
  17. {
  18. usedIDs = new List<int>();
  19. }
  20. /// <summary>
  21. /// Returns the next unused (lowest) ID.
  22. /// </summary>
  23. /// <returns>the next unused ID</returns>
  24. public int getNextUnusedID()
  25. {
  26. int id = 1;
  27. while (usedIDs.Contains(id))
  28. id++;
  29. usedIDs.Add(id);
  30. return id;
  31. }
  32. /// <summary>
  33. /// Removes the given ID from the used IDs.
  34. /// </summary>
  35. /// <param name="id">the unused ID</param>
  36. public void setIDUnused(int id)
  37. {
  38. usedIDs.Remove(id);
  39. }
  40. }
  41. }