views:

1313

answers:

3

I want to validate a value against values retrieved from a result set's first column. I have to do the same validation operation approximately 1000 times. So, I want to decrease the time complexity of this comparison from O(n) to constant. Is there some function through which I can put all of the values of result set's column into a hashmap without iterating?

+4  A: 

Short answer: no

Maurice Perry
+2  A: 

(I assume you're talking about a JDBC ResultSet). No, but that isn't a problem for you. It took O(n) to generate the ResultSet, so you shouldn't be worried about using O(n) more time to put them in a hashmap, or just do the validation against the whole ResultSet directly.

Keith Randall
... not to mention that the client-side cost of iterating and building the HashMap is likely to have a much smaller 'constant of proportionality' than the cost of doing the query and transmitting the data.
Stephen C
+1  A: 

Is it possible to do the validation as part of the database query itself (in the where clause) by passing the value from your code to the query ?

Rahul