views:

47

answers:

1

I am listening to a 3rd party web-service, when the services starts it generates a stream of objects which I am receiving. I have to search for a specific object within given amount of time and do some processing if the object is found or throw an error in any of the below condition:

  1. The web-service stops and I haven't found the object.
  2. My timer expires.
  3. Any other erroneous condition.

I am wondering about what could be the best way to search for the object assuming I am searching in an infinite list and the order of items in which they appear in the list cannot be predicted ?

+4  A: 

If the order cannot be predicted, then there's no better way than simply testing each object as it is received.

Blorgbeard
I was thinking of some way like storing first 1000 objects in a temp list and use a better search technique, but am curios if this can be made better
Ravi Gupta
I'm not sure what search technique you could use that would be better than a single pass through the list. Since there is no ordering, you can't binary search (for example) without first sorting the list. I'm not an expert on search algos, but.. it doesn't seem possible to me.
Blorgbeard
Blorgbeards solution is the best because to "use a better search technique" you have to organize your objects and to do that you will have to test them all anyway...
pgras