Search Algorithm (with an already implemented sorting algorithm)

I am making a Java application and Im having some doubts about performance.

I have a PriorityQueue that ensures that the deleted item is the one with the highest priority. This PriorityQueue has instances of the Event class (which implements the Comparable interface). Each event is associated with an entity .

The size of this priority can be huge, and very often I will have to delete events related to the entity.

Right now I am using an iterator to run all priority. However, I find it difficult, and I wonder if there are better alternatives for finding and deleting events related to the "xpto" entity.

Any suggestions?

Thank!

+3
source share
5 answers

There are several options:

  • Could you use separate queues for each organization? So when you get an event for "xpto" did you put it in XptoPriorityQueue? This will reduce the size of each queue, but may also lead to some other management issues.
  • Do you delete events for a specific object to handle them earlier? If so, then you just need to give these entities a higher priority and elevate them to the top of the queue.
  • Are you deleting events for a specific object to remove them from the queue and ignore them? If therefore they either should never queue or should receive a lower priority.
+1
source

:

  • , , . , O (log n).
  • , . , , Event, , , .
+1

remove , O (N * N).

PriorityQueue (, removeIf), remove, O (N log (N)).

0

, PriorityQueue Set, :

  • , Set , , PriorityQueue.
  • , Set.
  • , PriorityQueue , Set . .
0

, . , O (logN). , , , , HashMap (, , Entity ).

Then you can perform the usual heap operations, as for the priority queue, you just need to update the hash map mappings every time the event moves. To delete an event, find the index of this event in the hash table and perform the delete operation on the heap, starting from this index.

0
source

Source: https://habr.com/ru/post/1746595/


All Articles