TrackIDPool.cs 1.2 KB

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