/src/lib/storage/queue.e

http://github.com/tybor/Liberty · Specman e · 79 lines · 41 code · 7 blank · 31 comment · 0 complexity · faa10d499564b96a6bd31046147c5236 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class QUEUE[E_]
  5. --
  6. -- A Queue of elements of type `E_'.
  7. --
  8. insert
  9. RING_ARRAY[E_]
  10. rename add as collection_add,
  11. add_last as add,
  12. remove as collection_remove,
  13. remove_first as remove,
  14. make as collection_make,
  15. with_capacity as collection_with_capacity
  16. export {ANY} is_empty, add, remove, first, count;
  17. {QUEUE} all
  18. redefine
  19. new_iterator
  20. end
  21. ANY
  22. -- To get reasonable default exports
  23. undefine out_in_tagged_out_memory, copy, is_equal, default_create
  24. end
  25. create {ANY}
  26. make, with_capacity
  27. create {RING_ARRAY}
  28. collection_make
  29. feature {}
  30. make
  31. -- Create an empty array. Also consider `with_capacity',
  32. -- since growing a full queue is rather expensive.
  33. do
  34. with_capacity(16)
  35. ensure
  36. is_empty
  37. end
  38. with_capacity (needed_capacity: INTEGER)
  39. -- Create an empty array with capacity initialized
  40. -- at least to `needed_capacity'
  41. require
  42. needed_capacity >= 0
  43. do
  44. collection_with_capacity(needed_capacity, 1)
  45. end
  46. new_iterator: ITERATOR[E_]
  47. do
  48. check
  49. False
  50. end
  51. end
  52. end -- class QUEUE
  53. --
  54. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  55. --
  56. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  57. -- of this software and associated documentation files (the "Software"), to deal
  58. -- in the Software without restriction, including without limitation the rights
  59. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  60. -- copies of the Software, and to permit persons to whom the Software is
  61. -- furnished to do so, subject to the following conditions:
  62. --
  63. -- The above copyright notice and this permission notice shall be included in
  64. -- all copies or substantial portions of the Software.
  65. --
  66. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  67. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  68. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  69. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  70. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  71. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  72. -- THE SOFTWARE.