/src/lib/abilities/traversable.e

http://github.com/tybor/Liberty · Specman e · 62 lines · 19 code · 3 blank · 40 comment · 1 complexity · ee8d97a793536a94f22b47c0420d234c MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class TRAVERSABLE[E_]
  5. -- A `TRAVERSABLE[E_]' is a finite readable sequence of objects of type E_.
  6. -- For instance, `COLLECTION's and `STRING's are `TRAVERSABLE'.
  7. --
  8. -- A good performance should always be obtained by sequentially accessing a `TRAVERSABLE' with increasing
  9. -- indexes (from `lower' to `upper'), as demonstrated in the following code snippet :
  10. --
  11. -- from
  12. -- i := a_traversable.lower
  13. -- until
  14. -- i > a_traversable.upper
  15. -- loop
  16. -- do_something_with(a_traversable.item(i))
  17. -- i := i + 1
  18. -- end
  19. --
  20. -- Other accessing methods (including random access and sequential access from `upper' to `lower') may or
  21. -- may not lead to acceptable performance, depending on the particular implementation of `TRAVERSABLE'.
  22. inherit
  23. ITERABLE[E_]
  24. undefine -- because INDEXABLE features are more performant
  25. for_each, for_all, exists, aggregate,
  26. out_in_tagged_out_memory
  27. end
  28. INDEXABLE[E_]
  29. feature {ANY}
  30. enumerate: ENUMERATE[E_]
  31. local
  32. items: TRAVERSABLE[E_]
  33. do
  34. if items ?:= Current then
  35. items ::= Current
  36. create Result.make(items)
  37. end
  38. end
  39. end -- class TRAVERSABLE
  40. --
  41. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  42. --
  43. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  44. -- of this software and associated documentation files (the "Software"), to deal
  45. -- in the Software without restriction, including without limitation the rights
  46. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  47. -- copies of the Software, and to permit persons to whom the Software is
  48. -- furnished to do so, subject to the following conditions:
  49. --
  50. -- The above copyright notice and this permission notice shall be included in
  51. -- all copies or substantial portions of the Software.
  52. --
  53. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  54. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  55. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  56. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  57. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  58. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  59. -- THE SOFTWARE.