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
3478
votes
21 answers

How can I add new keys to a dictionary?

How do I add a new key to an existing dictionary? It doesn't have an .add() method.
lfaraone
  • 49,562
  • 17
  • 52
  • 70
1064
votes
16 answers

Why dict.get(key) instead of dict[key]?

I came across the dict method get which, given a key in the dictionary, returns the associated value. For what purpose is this function useful? If I wanted to find a value associated with a key in a dictionary, I can just do dict[key], and it…
stensootla
  • 13,945
  • 9
  • 45
  • 68
292
votes
9 answers

How can I get the index of an item in a list in a single step?

How can I find the index of an item in a list without looping through it? Currently this doesn't look very nice - searching through the list for the same item twice, just to get the index: var oProp = something; int theThingIActuallyAmInterestedIn…
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112
228
votes
6 answers

pandas loc vs. iloc vs. at vs. iat?

Recently began branching out from my safe place (R) into Python and and am a bit confused by the cell localization/selection in Pandas. I've read the documentation but I'm struggling to understand the practical implications of the various…
scribbles
  • 4,089
  • 7
  • 22
  • 29
198
votes
12 answers

How can I lookup a Java enum from its String value?

I would like to lookup an enum from its string value (or possibly any other value). I've tried the following code but it doesn't allow static in initialisers. Is there a simple way? public enum Verbosity { BRIEF, NORMAL, FULL; private…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
189
votes
6 answers

What is the point of Lookup?

The MSDN explains Lookup like this: A Lookup resembles a Dictionary. The difference is that a Dictionary maps keys to single values, whereas a Lookup maps keys to collections of…
dan-gph
  • 16,301
  • 12
  • 61
  • 79
187
votes
2 answers

How to lookup from and insert into a HashMap efficiently?

I'd like to do the following: Lookup a Vec for a certain key, and store it for later use. If it doesn't exist, create an empty Vec for the key, but still keep it in the variable. How to do this efficiently? Naturally I thought I could use…
Yusuke Shinyama
  • 1,873
  • 2
  • 11
  • 5
101
votes
7 answers

Working with dictionaries/lists to get list of keys

I have trivial question: I couldn't find a dictionary data structure in R, so I used list instead (like "word"->number). So, how do I get the list of keys.
Ivri
  • 2,159
  • 5
  • 25
  • 33
98
votes
2 answers

Function with same name but different signature in derived class not found

I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class's function in another class that inherits from the derived, I receive an error. See the following code: class…
Igor
  • 26,650
  • 27
  • 89
  • 114
95
votes
9 answers

How to do vlookup and fill down (like in Excel) in R?

I have a dataset about 105000 rows and 30 columns. I have a categorical variable that I would like to assign it to a number. In Excel, I would probably do something with VLOOKUP and fill. How would I go about doing the same thing in R? Essentially,…
user2142810
  • 1,143
  • 2
  • 9
  • 8
79
votes
2 answers

MongoDB nested lookup with 3 levels

I need to retrieve the entire single object hierarchy from the database as a JSON. Actually, the proposal about any other solution to achieve this result would be highly appreciated. I decided to use MongoDB with its $lookup support. So I have three…
Yuriy
  • 1,384
  • 1
  • 11
  • 17
79
votes
17 answers

Which is faster, Hash lookup or Binary search?

When given a static set of objects (static in the sense that once loaded it seldom if ever changes) into which repeated concurrent lookups are needed with optimal performance, which is better, a HashMap or an array with a binary search using some…
TheSoftwareJedi
  • 34,421
  • 21
  • 109
  • 151
69
votes
5 answers

MongoDB aggregation with $lookup only include (or project) some fields to return from query

In mongo, after doing an aggregation with $lookup, I would like the request to return only some fields and not the whole document. I have the following query : db.somecollection.aggregate([{ $lookup: { from: "campaigns", …
Samuel Rondeau-Millaire
  • 1,100
  • 2
  • 13
  • 24
66
votes
16 answers

What's an appropriate search/retrieval method for a VERY long list of strings?

This is not a terribly uncommon question, but I still couldn't seem to find an answer that really explained the choice. I have a very large list of strings (ASCII representations of SHA-256 hashes, to be exact), and I need to query for the presence…
Grant H.
  • 3,689
  • 2
  • 35
  • 53
66
votes
9 answers

Fast computing of log2 for 64-bit integers

A great programming resource, Bit Twiddling Hacks, proposes (here) the following method to compute log2 of a 32-bit integer: #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n static const char LogTable256[256] = { -1, 0, 1, 1, 2, 2,…
Desmond Hume
  • 8,037
  • 14
  • 65
  • 112
1
2 3
99 100