TrackIDPool.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. usedIDs = new List<int>();
  22. }
  23. /// <summary>
  24. /// Returns the next unused (lowest) ID.
  25. /// </summary>
  26. /// <returns>the next unused ID</returns>
  27. public int getNextUnusedID()
  28. {
  29. int id = 1;
  30. while (usedIDs.Contains(id))
  31. id++;
  32. usedIDs.Add(id);
  33. return id;
  34. }
  35. /// <summary>
  36. /// Removes the given ID from the used IDs.
  37. /// </summary>
  38. /// <param name="id">the unused ID</param>
  39. public void setIDUnused(int id)
  40. {
  41. usedIDs.Remove(id);
  42. }
  43. }
  44. }