Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Need suggestion on data structure

Reply
Thread Tools

Need suggestion on data structure

 
 
John
Guest
Posts: n/a
 
      01-21-2004
Hi:

I'd like to implement a simple map, which is a 2-D plane with many
points, e.g., 100. The points are not evenly distributed, i.e., some
points may have two neighbor points; some may have 5 or 6 neighbor
points. Could anyone suggest me a data structure for it.

Thanks in advance.

John
 
Reply With Quote
 
 
 
 
David Fisher
Guest
Posts: n/a
 
      01-21-2004
"John" <> wrote:

> I'd like to implement a simple map, which is a 2-D plane with many
> points, e.g., 100. The points are not evenly distributed, i.e., some
> points may have two neighbor points; some may have 5 or 6 neighbor
> points. Could anyone suggest me a data structure for it.


I assume you mean "map" as in geography, rather than std::map (STL) ...

What is the map going to be used for (what operations will be required ?)

Using the word "neighbours" sounds like it is a grid with integral
coordinates (like a bitmap), as opposed to arbitrary floating point
coordinates - is that right ?

David F


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      01-22-2004
"David Fisher" <> wrote in message news:<gNCPb.21$>...
> "John" <> wrote:
>
> > I'd like to implement a simple map, which is a 2-D plane with many
> > points, e.g., 100. The points are not evenly distributed, i.e., some
> > points may have two neighbor points; some may have 5 or 6 neighbor
> > points. Could anyone suggest me a data structure for it.

>
> I assume you mean "map" as in geography, rather than std::map (STL) ...
>
> What is the map going to be used for (what operations will be required ?)
>
> Using the word "neighbours" sounds like it is a grid with integral
> coordinates (like a bitmap), as opposed to arbitrary floating point
> coordinates - is that right ?
>
> David F


Thanks.
Yes. It is a geographic map, a 2-D plane with many points. Each point
has coordinates, (x,y). But the points are not evenly distributed. So
it is not a uniform grid. The operations are: insertion( add new
points), deletion( remove existing points), lookup( given a point,
output its coordinates), and searching (given a point, ouput its
neighbor points). Hope I have clearly described the problem. Any
suggestion is appreciated.

John
 
Reply With Quote
 
David Fisher
Guest
Posts: n/a
 
      01-22-2004
"John" <> wrote:

> > I assume you mean "map" as in geography, rather than std::map (STL) ...
> >
> > What is the map going to be used for (what operations will be required

?)
> >
> > Using the word "neighbours" sounds like it is a grid with integral
> > coordinates (like a bitmap), as opposed to arbitrary floating point
> > coordinates - is that right ?
> >
> > David F

>
> Thanks.
> Yes. It is a geographic map, a 2-D plane with many points. Each point
> has coordinates, (x,y). But the points are not evenly distributed. So
> it is not a uniform grid. The operations are: insertion( add new
> points), deletion( remove existing points), lookup( given a point,
> output its coordinates), and searching (given a point, ouput its
> neighbor points). Hope I have clearly described the problem. Any
> suggestion is appreciated.


I am still not clear on "neighbour points" in this context - does this mean,
all points within a certain radius ?

There are a few different data structures which might be useful (probably
off topic now ):

- a 2D grid of "bins" (a list of points for each grid cell), similar to a
hash table - point x, y maps to bin[x / CELL_SIZE][y / CELL_SIZE]. To search
for points near point P, iterate through the points in P's bin and the 8
adjacent bins (assuming you are only interesting in points within a distance
of CELL_SIZE from P)
- Quad Trees are a great recursive data structure for uneven distributions
of points ("bins" are only good for reasonably scattered distributions).
These are like a binary tree in two dimensions (with four children instead
of two)
- search for "spatial data structures" with google for others

Hope this is helpful,

David F


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      01-22-2004
"David Fisher" <> wrote in message news:<SIJPb.52$>...
> "John" <> wrote:
>
> > > I assume you mean "map" as in geography, rather than std::map (STL) ...
> > >
> > > What is the map going to be used for (what operations will be required

> ?)
> > >
> > > Using the word "neighbours" sounds like it is a grid with integral
> > > coordinates (like a bitmap), as opposed to arbitrary floating point
> > > coordinates - is that right ?
> > >
> > > David F

> >
> > Thanks.
> > Yes. It is a geographic map, a 2-D plane with many points. Each point
> > has coordinates, (x,y). But the points are not evenly distributed. So
> > it is not a uniform grid. The operations are: insertion( add new
> > points), deletion( remove existing points), lookup( given a point,
> > output its coordinates), and searching (given a point, ouput its
> > neighbor points). Hope I have clearly described the problem. Any
> > suggestion is appreciated.

>
> I am still not clear on "neighbour points" in this context - does this mean,
> all points within a certain radius ?
>
> There are a few different data structures which might be useful (probably
> off topic now ):
>
> - a 2D grid of "bins" (a list of points for each grid cell), similar to a
> hash table - point x, y maps to bin[x / CELL_SIZE][y / CELL_SIZE]. To search
> for points near point P, iterate through the points in P's bin and the 8
> adjacent bins (assuming you are only interesting in points within a distance
> of CELL_SIZE from P)
> - Quad Trees are a great recursive data structure for uneven distributions
> of points ("bins" are only good for reasonably scattered distributions).
> These are like a binary tree in two dimensions (with four children instead
> of two)
> - search for "spatial data structures" with google for others
>
> Hope this is helpful,
>
> David F


Hi David:
Thanks a lot.

|---------------------------------------|
| |
| b* |
| * * * |
| |
| * 1* 2* |
| |
| 4* P* 3* |
| |
| * 5* 6* |
| |
| * * c* * |
| |
| * * * |
|---------------------------------------|

I use the figure above to clarify the meaning of "neighbor". The above
figure is a 2-D plane. A "*" indicates a point. The neighbors of point
P are 1,2,3,4,5,and 6, but not b and c, since points b and c are too
far from P. So I may specify a radius.
To make the problem easier, I only need two operations: lookup( given
a point,
output its coordinates), and searching (given a point, ouput its
neighbor points). I think that insertion and deletion may be too
difficult, since points change. Any suggestion is appreciated.

John
 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      01-23-2004
John wrote:
>
>
> Hi David:
> Thanks a lot.
>
> |---------------------------------------|
> | |
> | b* |
> | * * * |
> | |
> | * 1* 2* |
> | |
> | 4* P* 3* |
> | |
> | * 5* 6* |
> | |
> | * * c* * |
> | |
> | * * * |
> |---------------------------------------|
>
> I use the figure above to clarify the meaning of "neighbor". The above
> figure is a 2-D plane. A "*" indicates a point. The neighbors of point
> P are 1,2,3,4,5,and 6, but not b and c, since points b and c are too
> far from P. So I may specify a radius.
> To make the problem easier, I only need two operations: lookup( given
> a point,
> output its coordinates), and searching (given a point, ouput its
> neighbor points). I think that insertion and deletion may be too
> difficult, since points change. Any suggestion is appreciated.
>


One more thing: Is the number of points fixed or does it change a lot
(during one program run). The reason is: It's easy to come up with
a data structure that simply stores the neighborhood information for
a point. You create it once (and update it if necc.) and
simply use that instead of scanning the neighborhood each time you
need that information. If the points stay constant during a program run,
this is probably the fastest thing.
If on the other hand the points are constantly moving you need a more dynamic
approach.

--
Karl Heinz Buchegger

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: data structure suggestion (native python datatypes or sqlite;compound select) Dennis Lee Bieber Python 0 09-18-2010 11:48 PM
Re: data structure suggestion (native python datatypes or sqlite;compound select) Vlastimil Brom Python 0 09-18-2010 09:00 PM
Re: data structure suggestion (native python datatypes or sqlite;compound select) MRAB Python 0 09-17-2010 12:18 AM
Re: data structure suggestion (native python datatypes or sqlite;compound select) MRAB Python 0 09-16-2010 11:17 PM
data structure suggestion (native python datatypes or sqlite;compound select) Vlastimil Brom Python 0 09-16-2010 10:11 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57