Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate range checking

Status
Not open for further replies.

bsanthu

Programmer
Oct 31, 2002
14
IN
Hi all,
I am using grid control to get a range of values

for eg,
col1 col2 col3
1 5 range1
6 10 range2
11 15 range3

Here I want to check the duplicate range checking before reading.

for eg
1 5 range1

and if
3 5 range2

occurs I have to raise error. I could not find the logic to check the duplicate range here.
For the above case all the following ranges are invalid or duplicate for 1 to 5 range
1 5 (duplicate)
1 3 ( already covered in range 1-5)
0 10 ( over covered by this range)
0 5 (over covered)
2 10 (intersecting range)


Any one knows the idea? if possible I need the code...

-Thanks in advance
Santhakumar B
 
This looks fairly trivial!

Just loop through the ranges checking:
1. if the low value is within any existing range
2. If the high value is within any existing range
3. If any existing low is within this range
4. If any existing high is within this range
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
One approach that you can take is to create an array from 0 to the highest range value that exists.

Initialize the array to 0.
Walk thru the grid and for each row,
loop thru the array form the lower value to the upper value
if the value is 0, then set it 1
if the value is 1, then you have an overlap

You can adjust this basic method to account for all of error conditions you describe.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
the logic for testing overlapping regions (2d) is as follow

IF Object1.Start <= Object2.End AND
Object1.End >= Object2.Start Then
'intersection is true
END IF

IE
Code:
Object 1         I-----I
Object 2      I-----I
Object 3             I-----I
Object 4           I-I
Object 5      I----------I
Object 6 I-----I
Object 7                 I-----I
Objects 1 is our base object
Objects 2,3,4,5 all interset object 1 and are caught by the code above
Objects 6 and 7 do not intersect Object 1
 
SemperFiDownUnda - There is no doubt that the intersection method will work, and in fact is a preferred method in some cases. However in this case, I think the establishing the array map would be more efficient since each range has only to be checked once against the array map. But doesn't the intersection method require that range 1 be compared with all the ranges 2 to n, then range 2 against 3 to n, down to the final compare of n-1 to n. It just seems to me that in this case, the array map may be more efficient. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The Objects can be in an array

so you grab object 1 from Array Pos 1
check object agiast Array Pos 2 - n
grab Array Pos 2 compair to Pos 3 - n

easy done with a loop
 
Hi all,
This is a good logic given by you and discussed by peoples.I have put the values in array and looped thru it. Thanks a lot for you all.

-Regards
Santhakumar B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top