I have a field which takes values from 0 to 6,00,000.
For this field values in database are say 5,6,7,8,45,91,92,93,94.
I have to get free values and used value suggestions for this field.
1.USED
Minvalue= 0 maxvalue=94( from database)
i use a for loop (i=minvalue;i<=maxvalue;i++)
Loop runs 94 times in this case and each time it checks if something matches database entries (5,6,7,45..94).
I print output ranges like.
Used values:
5 to 8
45
91 to 94
Since values are less it works fast. If there was even one entry like 490000 in database then loop would have run for a very long time.
2. FREE
Min value= 0 maxvalue = 600000 (from field definition)
I have the same for loop concept here too so the loop runs 500000 times. And output comes after a long time. It is too time consuming.
I would want output like.
Free values :
0 to 4
9 to 44
46 to 90
95-600000
Any way to reduce for loop executions or use some other logic.