PriorityQueueState.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // PriorityQueueState.cs
  3. //
  4. // Author:
  5. // Marek Habersack <[email protected]>
  6. //
  7. // Copyright (c) 2010, Marek Habersack
  8. //
  9. // All rights reserved.
  10. //
  11. // Redistribution and use in source and binary forms, with or without modification, are permitted
  12. // provided that the following conditions are met:
  13. //
  14. // * Redistributions of source code must retain the above copyright notice, this list of
  15. // conditions and the following disclaimer.
  16. // * Redistributions in binary form must reproduce the above copyright notice, this list of
  17. // conditions and the following disclaimer in the documentation and/or other materials
  18. // provided with the distribution.
  19. // * Neither the name of Marek Habersack nor the names of its contributors may be used to
  20. // endorse or promote products derived from this software without specific prior written
  21. // permission.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. using System;
  36. using System.Collections.Generic;
  37. using System.Web.Caching;
  38. using BenTools.Data;
  39. namespace Tester
  40. {
  41. class PriorityQueueState
  42. {
  43. public readonly BinaryPriorityQueue Queue;
  44. public readonly string ListName;
  45. public readonly string QueueName;
  46. public readonly string ItemName;
  47. public int EnqueueCount;
  48. public int DequeueCount;
  49. public int DisableCount;
  50. public int PeekCount;
  51. public PriorityQueueState (string listName, string queueName, string itemName)
  52. {
  53. Queue = new BinaryPriorityQueue (new CacheItemComparer ());
  54. EnqueueCount = 0;
  55. DequeueCount = 0;
  56. DisableCount = 0;
  57. PeekCount = 0;
  58. ListName = listName;
  59. QueueName = queueName;
  60. ItemName = itemName;
  61. }
  62. public void Enqueue (CacheItem item)
  63. {
  64. Queue.Push (item);
  65. }
  66. public CacheItem Dequeue ()
  67. {
  68. return Queue.Pop () as CacheItem;
  69. }
  70. public CacheItem Peek ()
  71. {
  72. return Queue.Peek () as CacheItem;
  73. }
  74. }
  75. }