I am creating my own priority queue of sorts. It is not a typical priority queue in that items are inserted with a given priority. Rather items can be added to the queue and they begin at the highest priority(let say we have 5 queues, queue 1=highest priority, queue5=lowest)), so the item is added to queue 1 initially.
The user of this data structure can get the next() element, which returns an element based on some factors that I am interested in, namely the priority, but it is not dequeued from the entire data structure. The user provides some feedback to the validity of the item returned from the previous call to next()(eg. a pass/fail result), and based on that, the item is moved up or down in priority. Basically, elements that fail get used less often and I have mechanisms to eventually remove elements that fail too often.
1)Any suggestions to improve the interface? I do not like having to retrieve an element from the next() call and then provide feedback with another function call. There is too much room for error where the state gets messed up. (ie user does not report result before getting next element..etc…). Also, it would be desireable to allow this to be thread safe.
2)I am using a private nested class that wraps the elements I am interested in along with some attributes associated with each element to track statistics on the element(eg pass/fail counts etc…), and would like to know if there was a way to access the outer class members from the inner class?
Not sure I understand the question exactly, but what is wrong with the next() not waiting for the returned feedback? Users of the structure pull the next() element out of the queue and then submitFeedback() on the element when they are ready. Meanwhile, other users can pull out the next() elements as well, asynchronously. The queue handles calls as they come in. If this doesn’t help, could you explain the problem with handling state in more detail?