Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30701

fastest data structure for retrieving objects identified by (x,y) tuple?

Date 2012-10-03 18:30 -0400
From Benjamin Jessup <bsj@abzinc.com>
Subject fastest data structure for retrieving objects identified by (x,y) tuple?
Newsgroups comp.lang.python
Message-ID <mailman.1777.1349303447.27098.python-list@python.org> (permalink)

Show all headers | View raw


I have a group of objects identified by unique (x,y) pairs and I want to 
find out an object's "neighbors" in a matrix of size 2400 x 2400.
        #############
        #obj#   #   #
        #############
        #   #   #obj#      3 x 3 Example
        #############
        #   #   #   #
        #############
There is either a neighbor, or a null value. I always know the (x,y) 
pair to check the neighbors of, so is doing,
 >> obj = grid[x][y] #lists, doesn't scale with num of objects
or,
 >> obj = grid.get((x,y),None) #dictionary, scales with num of objects
the fastest? I can't seem to find a conclusion by testing each alone, 
then in the full environment. Is it that, depending on the number of 
objects, each has an advantage?

I know the fastest way to retrieve them would be to have them store 
pointers to their neighbors, then use those for retrieval. When large 
numbers of objects are changing their (x,y) pairs, rebuilding the 
pointers is too slow.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

fastest data structure for retrieving objects identified by (x,y) tuple? Benjamin Jessup <bsj@abzinc.com> - 2012-10-03 18:30 -0400
  Re: fastest data structure for retrieving objects identified by (x,y) tuple? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-04 01:58 +0000
    Re: fastest data structure for retrieving objects identified by (x,y) tuple? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-04 02:25 +0000
    Re: fastest data structure for retrieving objects identified by (x,y) tuple? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-04 18:11 +0200
      Re: fastest data structure for retrieving objects identified by (x,y) tuple? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-04 23:37 +0000

csiph-web