indexing

What does IndexOutofRangeException mean?

ε祈祈猫儿з 提交于 2019-12-18 09:46:01
问题 It says that in my array that I have gone over the index. My program is a Number Guessing game played by 5 players (5 indexes). I have used arrays to create the object and player classes. I have reached a stump where my program crashes within the second or third round of the game. I noticed that during my second round, the index did not loop property: the loop counts the index 1 to 5 in the first loop, then counts 2 to 5 in the second loop, then if I even get to the 3rd round of the loop, all

Check if property name is array index

我与影子孤独终老i 提交于 2019-12-18 09:13:28
问题 I want to assign some properties to an array, but only if they are array indices. Otherwise some implementations might switch the underlying structure to a hash table and I don't want that. For example, these are array indices: "0" , "1" , "2" , "3" , "4" , "4294967294" But these are not: "abcd" , "0.1" , "-0" , "-1" , " 2" , "1e3" , "4294967295" Is there an easy way to test if a string is an array index? 回答1: In ECMAScript 5, Array indices are defined as follows: A property name P (in the

Proposal: locally unique GUID alternative

安稳与你 提交于 2019-12-18 09:10:13
问题 The problem I'm looking for feedback on this exploration of a locally unique alternative for GUIDs , with the following requirements: Has very low chance of collisions (to the point that we'd rather collide once a year than perform checks) Does not leak sensitive information, such as how many items exist Has high performance in an SQL database Is copy/pastable for manual querying (as both query string and query result) Is usable as a URI component without encoding To meet the requirements, I

How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?

余生颓废 提交于 2019-12-18 09:04:19
问题 Also I want to know how to add meta data while indexing so that i can boost some parameters 回答1: Lucene indexes text not files - you'll need some other process for extracting the text out of the file and running Lucene over that. 回答2: There are several frameworks for extracting text suitable for Lucene indexing from rich text files (pdf, ppt etc.) One of them is Apache Tika, a sub-project of Lucene. Apache POI is a more general document handling project inside Apache. There are also some

Is it possible to reference a specific element of an anonymous array in PHP?

醉酒当歌 提交于 2019-12-18 08:39:49
问题 This is probably a simple question, and I'm afraid the answer might be "no", but... Here's a simple piece of code: function func1() { $bt = debug_backtrace(); print "Previous function was " . $bt[1]['function'] . "\n"; } Now... Can this be done without the temporary variable? In another language, I might expect to be able to say: function func1() { print "Previous function was " . (debug_backtrace())[1]['function'] . "\n"; } Alas, in PHP, this results in an error: PHP Parse error: syntax

How to access array internal index with postgreSQL?

放肆的年华 提交于 2019-12-18 08:29:10
问题 This is my (perhaps usual for you) non-optimized solution: Workaround for PG problem with non-optimized internal function: CREATE FUNCTION unnest_with_idx(anyarray) RETURNS TABLE(idx integer, val anyelement) AS $$ SELECT generate_series(1,array_upper($1,1)) as idx, unnest($1) as val; $$ LANGUAGE SQL IMMUTABLE; Test: SELECT idx,val from unnest_with_idx(array[1,20,3,5]) as t; But, as I said, non-optimized . I can't believe (!!) that PostgreSQL doesn't have an internal index for arrays ... ? But

How to access array internal index with postgreSQL?

旧巷老猫 提交于 2019-12-18 08:28:00
问题 This is my (perhaps usual for you) non-optimized solution: Workaround for PG problem with non-optimized internal function: CREATE FUNCTION unnest_with_idx(anyarray) RETURNS TABLE(idx integer, val anyelement) AS $$ SELECT generate_series(1,array_upper($1,1)) as idx, unnest($1) as val; $$ LANGUAGE SQL IMMUTABLE; Test: SELECT idx,val from unnest_with_idx(array[1,20,3,5]) as t; But, as I said, non-optimized . I can't believe (!!) that PostgreSQL doesn't have an internal index for arrays ... ? But

Partial Index not used in ON CONFLICT clause while performing an upsert in Postgresql

余生长醉 提交于 2019-12-18 08:25:26
问题 I have the following Entity Attribute value table : CREATE TABLE key_value_pair ( id serial NOT NULL PRIMARY KEY, key varchar(255) NOT NULL, value varchar(255), is_active boolean ); CREATE UNIQUE INDEX key_value_pair_key_if_is_active_true_unique ON key_value_pair (key) WHERE is_active = true; Sample entries in this table are : id | key | value | is_active ----+-------------+-------+----------- 1 | temperature | 2 | f 2 | temperature | 12 | f 3 | temperature | 15 | f 4 | temperature | 19 | f 5

How can I optimize this SQL query (Using Indexes)? [closed]

孤人 提交于 2019-12-18 07:22:43
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . There is a query which runs more slowly than I would like, but I cannot share the details. The query returns the correct results already, and I have refactored it, but I cannot get it to run quickly enough. The

How to read index data as string with pandas.read_csv()?

那年仲夏 提交于 2019-12-18 06:54:33
问题 I'm trying to read csv file as DataFrame with pandas, and I want to read index row as string. However, since the row for index doesn't have any characters, pandas handles this data as integer. How to read as string? Here are my csv file and code: [sample.csv] uid,f1,f2,f3 01,0.1,1,10 02,0.2,2,20 03,0.3,3,30 [code] df = pd.read_csv('sample.csv', index_col="uid" dtype=float) print df.index.values The result: df.index is integer, not string: >>> [1 2 3] But I want to get df.index as string: >>>