doc.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Package deque provides a fast ring-buffer deque (double-ended queue)
  3. implementation.
  4. Deque generalizes a queue and a stack, to efficiently add and remove items at
  5. either end with O(1) performance. Queue (FIFO) operations are supported using
  6. PushBack and PopFront. Stack (LIFO) operations are supported using PushBack and
  7. PopBack.
  8. # Ring-buffer Performance
  9. The ring-buffer automatically resizes by powers of two, growing when additional
  10. capacity is needed and shrinking when only a quarter of the capacity is used,
  11. and uses bitwise arithmetic for all calculations.
  12. The ring-buffer implementation significantly improves memory and time
  13. performance with fewer GC pauses, compared to implementations based on slices
  14. and linked lists.
  15. For maximum speed, this deque implementation leaves concurrency safety up to
  16. the application to provide, however the application chooses, if needed at all.
  17. # Reading Empty Deque
  18. Since it is OK for the deque to contain the zero-value of an item, it is
  19. necessary to either panic or return a second boolean value to indicate the
  20. deque is empty, when reading or removing an element. This deque panics when
  21. reading from an empty deque. This is a run-time check to help catch programming
  22. errors, which may be missed if a second return value is ignored. Simply check
  23. Deque.Len() before reading from the deque.
  24. # Generics
  25. Deque uses generics to create a Deque that contains items of the type
  26. specified. To create a Deque that holds a specific type, provide a type
  27. argument to New or with the variable declaration.
  28. */
  29. package deque