hope icon indicating copy to clipboard operation
hope copied to clipboard

Define container behavior

Open xandkar opened this issue 10 years ago • 1 comments

Goal: swappable implementations

xandkar avatar Jan 03 '15 20:01 xandkar

Some common operations for a vague notion of a container could be:

  • empty
  • add
  • remove
  • find
  • length
  • is_empty
  • is_element

These are suitable for at least: list, set, stack, queue, heap, dictionary.

Being that each implementation defines a particular order, our collection is also a sequence, so ordered access can also make sense:

  • first
  • last
  • nth

There is a semantic conflict for a remove operation between a set and a queue/stack, since set removes a specific item and queue/stack remove whatever is at the top of the order. Can we come-up with an abstraction to accommodate both?

A heap is probably less of a problem, since it can be viewed as just an extension to the regular queue/stack interface.

xandkar avatar Jan 03 '15 22:01 xandkar