MCPcopy Create free account
hub / github.com/PyTables/PyTables / search

Method search

tables/index.py:2139–2235  ·  view source on GitHub ↗

Do a binary search in this index for an item.

(self, item: tuple[float, float])

Source from the content-addressed store, hash-verified

2137 self.dirtycache = False
2138
2139 def search(self, item: tuple[float, float]) -> int:
2140 """Do a binary search in this index for an item."""
2141 if profile:
2142 tref = clock()
2143 if profile:
2144 show_stats("Entering search", tref)
2145
2146 if self.dirtycache:
2147 self.restorecache()
2148
2149 # An empty item or if left limit is larger than the right one
2150 # means that the number of records is always going to be empty,
2151 # so we avoid further computation (including looking up the
2152 # limits cache).
2153 if not item or item[0] > item[1]:
2154 self.starts[:] = 0
2155 self.lengths[:] = 0
2156 return 0
2157
2158 tlen = 0
2159 # Check whether the item tuple is in the limits cache or not
2160 nslot = self.limboundscache.getslot(item)
2161 if nslot >= 0:
2162 startlengths = self.limboundscache.getitem(nslot)
2163 # Reset the lengths array (not necessary for starts)
2164 self.lengths[:] = 0
2165 # Now, set the interesting rows
2166 for nrow2, start, length in startlengths:
2167 self.starts[nrow2] = start
2168 self.lengths[nrow2] = length
2169 tlen = tlen + length
2170 return tlen
2171 # The item is not in cache. Do the real lookup.
2172 sorted_ = self.sorted
2173 if self.nslices > 0:
2174 if self.type in self.opt_search_types:
2175 # The next are optimizations. However, they hide the
2176 # CPU functions consumptions from python profiles.
2177 # You may want to de-activate them during profiling.
2178 if self.type == "int32":
2179 tlen = sorted_._search_bin_na_i(*item)
2180 elif self.type == "int64":
2181 tlen = sorted_._search_bin_na_ll(*item)
2182 elif self.type == "float16":
2183 tlen = sorted_._search_bin_na_e(*item)
2184 elif self.type == "float32":
2185 tlen = sorted_._search_bin_na_f(*item)
2186 elif self.type == "float64":
2187 tlen = sorted_._search_bin_na_d(*item)
2188 elif self.type == "float96":
2189 tlen = sorted_._search_bin_na_g(*item)
2190 elif self.type == "float128":
2191 tlen = sorted_._search_bin_na_g(*item)
2192 elif self.type == "uint32":
2193 tlen = sorted_._search_bin_na_ui(*item)
2194 elif self.type == "uint64":
2195 tlen = sorted_._search_bin_na_ull(*item)
2196 elif self.type == "int8":

Callers 7

isvisiblepathFunction · 0.80
_table__where_indexedFunction · 0.80
create_indexesMethod · 0.80
get_versionFunction · 0.80
search_fileFunction · 0.80
search_fileFunction · 0.80

Calls 5

restorecacheMethod · 0.95
search_scalarMethod · 0.95
search_last_rowMethod · 0.95
show_statsFunction · 0.70
appendMethod · 0.45

Tested by 1

create_indexesMethod · 0.64