Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 187 characters in body
Source Link
mikera
  • 106.5k
  • 28
  • 265
  • 427

The question doesn't provide muchany detail on what you want to do with this. And this is very important, because the usage pattern is critical in determining which data structure is going to be most efficient for your use case.

But I'd say that in the absence of other details, a HashTable of Queues sounds like a sensible choice, with the HashTable using the ID as a key and the corresponding Queue as a value.

Then the following operations will both be O(1) with very low overhead:

  • Add an item to the queue with a given ID
  • Pull the first item from the Queue with a given ID

Which is presumablyprobably the usage pattern you are going to be needing in most cases.....

The question doesn't provide much detail on what you want to do with this.

But I'd say that in the absence of other details, a HashTable of Queues sounds like a sensible choice, with the HashTable using the ID as a key and the corresponding Queue as a value.

Then the following operations will both be O(1):

  • Add an item to the queue with a given ID
  • Pull the first item from the Queue with a given ID

Which is presumably the usage pattern you are going to be needing.....

The question doesn't provide any detail on what you want to do with this. And this is very important, because the usage pattern is critical in determining which data structure is going to be most efficient for your use case.

But I'd say that in the absence of other details, a HashTable of Queues sounds like a sensible choice, with the HashTable using the ID as a key and the corresponding Queue as a value.

Then the following operations will both be O(1) with very low overhead:

  • Add an item to the queue with a given ID
  • Pull the first item from the Queue with a given ID

Which is probably the usage pattern you are going to be needing in most cases.....

Source Link
mikera
  • 106.5k
  • 28
  • 265
  • 427

The question doesn't provide much detail on what you want to do with this.

But I'd say that in the absence of other details, a HashTable of Queues sounds like a sensible choice, with the HashTable using the ID as a key and the corresponding Queue as a value.

Then the following operations will both be O(1):

  • Add an item to the queue with a given ID
  • Pull the first item from the Queue with a given ID

Which is presumably the usage pattern you are going to be needing.....