Questions tagged [lookup]

Look up is related to indexes and hash tables. It is the action of accessing fastly to an item in a large collection thanks to a index (a so-called lookup table).

In computer science, a lookup table is an array that replaces runtime computation with a simpler array indexing operation. The savings in terms of processing time can be significant, since retrieving a value from memory is often faster than undergoing an 'expensive' computation or input/output operation.

The tables may be precalculated and stored in static program storage, calculated (or "pre-fetched") as part of a program's initialization phase (memoization), or even stored in hardware in application-specific platforms. Lookup tables are also used extensively to validate input values by matching against a list of valid (or invalid) items in an array and, in some programming languages, may include pointer functions (or offsets to labels) to process the matching input.

3604 questions
14
votes
3 answers

Fastest way to find an item in a list?

I have an unsorted list of strings. I can place these items in an array, List, SortedList, whatever. I need to find the fastest way of looking up a string in this list. Am I better off dumping the list into an array, sorting it, then implementing…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
13
votes
8 answers

Reverse DNS lookup in perl

How do I perform a reverse DNS lookup, that is how do I resolve an IP address to its DNS hostname in Perl?
Joakim
  • 11,468
  • 9
  • 44
  • 50
13
votes
6 answers

What is the proper way to track indexes in python?

Right now I am tracking my index in side the loop like this index = 0 for entry in longList: if entry == 'foo': print index index += 1 is there a better way to do this?
John
  • 13,197
  • 7
  • 51
  • 101
13
votes
7 answers

Find-or-insert with only one lookup in C# Dictionary

I'm a former C++/STL programmer trying to code a fast marching algorithm using C#/.NET technology... I'm searching for an equivalent of STL method map::insert that insert a value at given key if not exists, else returns an iterator to the existing…
etham
  • 3,158
  • 2
  • 16
  • 13
13
votes
1 answer

When should I raise LookupError in python?

Python's built-in exception documentation defines LookupError as: The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: IndexError, KeyError. This can be raised directly by…
Veltzer Doron
  • 934
  • 2
  • 10
  • 31
13
votes
2 answers

How to lookup only for specific fields in mongo

How to join only specific fields? When using $lookup, mongo returns the whole document. Let's say that's my data: users [ { id: 0, name: "Bob", adj: 1 }, { id: 1, name: "Will", adj: 2 }, ] adjectives [ { id: 1, name: "awesome" }, {…
feerlay
  • 2,286
  • 5
  • 23
  • 47
13
votes
3 answers

Get value from dictionary for first key that exists

TL;DR Is there a Python dictionary method or simple expression that returns a value for the first key (from a list of possible keys) that exists in a dictionary? Details Lets say I have a Python dictionary with a number of key-value pairs. The…
Andrew Guy
  • 9,310
  • 3
  • 28
  • 40
13
votes
3 answers

Checking if Date is Between two Dates in R

I have two large datasets, df1 and df2. The first dataset, df1, contains the columns 'ID' and 'actual.data'. df1 <- data.frame(ID=c(1,1,1,2,3,4,4),…
michael
  • 412
  • 1
  • 3
  • 13
13
votes
2 answers

Making a grid-like data type in haskell

Problem I've been wondering how this could be done efficiently for a while, but for some reason I have been unable to do it. I need to model a rectangular grid, where each field contains some data. I need to access it via a zipper, where my focus is…
Undreren
  • 2,811
  • 1
  • 22
  • 34
13
votes
1 answer

Many to many lookups in Django

This is probably insultingly simple and worthy of a Nelson Muntz laugh, but I'm having a real braindead moment tryng to make many to many connections across various model relationships. I have the following models (simplified for your…
Steerpike
  • 17,163
  • 8
  • 39
  • 53
13
votes
2 answers

Converting Lookup into other data structures c#

I have a Lookup where the TElement refers to a string of words. I want to convert Lookup into: Dictionary or List> ? I have read some articles about using the Lookup but it…
FSm
  • 2,017
  • 7
  • 29
  • 55
12
votes
2 answers

$aggregation and $look up in the same collection- mongodb

The structure is more or less like; [ {id: 1, name: "alex" , children: [2, 4, 5]}, {id: 2, name: "felix", children: []}, {id: 3, name: "kelly", children: []}, {id: 4, name: "hannah", children: []}, {id: 5, name: "sonny",…
mmu36478
  • 1,295
  • 4
  • 19
  • 40
12
votes
9 answers

is locking necessary for Dictionary lookup?

lock(dictionaryX) { dictionaryX.TryGetValue(key, out value); } is locking necessary while doing lookups to a Dictionary ? THe program is multithreaded, and while adding key/value to dict. dict is being locked.
DarthVader
  • 52,984
  • 76
  • 209
  • 300
11
votes
2 answers

Mongodb - regex match of keys for subdocuments

I have some documents saved in a collection (called urls) that look like this: { payload:{ url_google.com:{ url:'google.com', text:'search' } } }, { payload:{ url_t.co:{ …
Matt P
  • 163
  • 1
  • 1
  • 4
11
votes
11 answers

Is there a publicly available list of the US States in machine readable form?

Where can I find a list of the US States in a form for importing into my database? SQL would be ideal, otherwise CSV or some other flat file format is fine. Edit: Complete with the two letter state codes
user59861