• Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 个月前

    But a ring buffer is a FIFO data structure that can be implemented using linked lists. What ring buffer implementation did you have in mind?

      • Eager Eagle@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        1
        ·
        2 个月前

        Since VecDeque is a ring buffer, its elements are not necessarily contiguous in memory.

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          2 个月前

          No that’s a subtly different thing. The storage is a contiguous vector, but because it is a ring buffer there must be one pair of adjacent elements that are not contiguous in memory. That’s what that comment is saying.

          But because it is only one discontinuity it doesn’t affect algorithmic complexity, so it is still O(1) to access elements, unlike a linked list which is O(N).

          If you google “circular buffer” there will be loads of diagrams that make it really obvious how it works.

    • CodeMonkey@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      2 个月前

      I am used to seeing ring buffers implemented using an array. They are FIFO if you write to the maximum offset and read from the minimum offset but they are double ended if you have a method to read from the maximum offset and write to the minimum offset.