Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'objects,': 0.07; "object's": 0.09; 'pointers': 0.09; 'slow.': 0.09; 'value.': 0.15; 'doing,': 0.16; 'neighbor,': 0.16; 'pairs': 0.16; 'pairs,': 0.16; 'received:192.168.1.16': 0.16; 'subject:fastest': 0.16; 'example': 0.23; 'testing': 0.24; 'header:User-Agent:1': 0.26; 'environment.': 0.27; 'scale': 0.27; 'skip:# 10': 0.27; "doesn't": 0.28; 'obj': 0.29; 'objects': 0.29; 'null': 0.33; 'subject:data': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; "can't": 0.34; 'or,': 0.34; 'fastest': 0.35; 'identified': 0.35; 'subject:?': 0.35; 'there': 0.35; 'too': 0.36; 'subject: (': 0.36; 'store': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'subject:,': 0.81; '2400': 0.84; 'alone,': 0.84; 'received:98.172': 0.84 Date: Wed, 03 Oct 2012 18:30:24 -0400 From: Benjamin Jessup User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: fastest data structure for retrieving objects identified by (x,y) tuple? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349303447 news.xs4all.nl 6946 [2001:888:2000:d::a6]:38217 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30701 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.