Skip to content
Advertisement

Efficiently search a long list of lists

I have a long list of hexahedral point coordinates, for example:

JavaScript

Each row defines a hexahedron cell, and by iterating over each cell, I extract the defining faces of the cell (6 faces), and add each face to a list processed_faces

enter image description here

All of this is fine, but because some cells are sharing the same face, I needed a way to check if the current face has been processed before or not (also needed later for connectivity calculations, so no way out of this).

JavaScript

The bottleneck of my code is face_exists(), for which I tried two different approaches:

  1. Sort each processed face, convert it to a tuple (to be hashable), add the tuple to a list of tuples, and simple check if a face exists by tuple(sorted(face)) in faces. But this is AWFULLY SLOW.

  2. Implement a trie data structure, which works just fine (and about 100x faster than method 1), but I am not satisfied with the performance

    JavaScript

Sorry for the long question, in summary I am looking for two things:

  1. An alternative data structure for mesh storage, that allows my fast search needs. OR:
  2. If trie is suitable for my application, is there a python library (hopefully with a C backend) that allows storing list of numbers, because libraries I came across are mostly designed for strings.

Advertisement

Answer

One of possible drop-in solutions would be to use a set/frozenset for storing faces. Sets have great lookup performance and are simple to use here.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement