indexing

How do I get the index of a newly added item in a list in C#?

筅森魡賤 提交于 2019-12-18 06:53:33
问题 When I add an item (an instance of a class) to a list, I need to know the index of the new item. Is it possible with any function? Example code: MapTiles.Add(new Class1(num, x * 32 + cameraX, y * 32 + cameraY)); 回答1: MapTiles.Count will give you the index of next item that will be added to the list Something like: Console.WriteLine("Adding " + MapTiles.Count + "th item to MapTiles List"); MapTiles.Add(new Class1(num, x * 32 + cameraX, y * 32 + cameraY)); 回答2: Class1 newTile = new Class1(num,

Sort MATLAB array in descending order

和自甴很熟 提交于 2019-12-18 06:49:47
问题 I am using MATLAB. I have a question about how to sort an matrix in descending order along one column of a matrix and have the rest of the row values follow suit. For example, A = [1 30; 2 40; 3 10; 4 50; 5 20] becomes B = [4 50; 2 40; 1 30; 5 20; 3 10] Thanks 回答1: Use the SORTROWS function, specifying that you want to sort using the second column in descending order... B = sortrows(A, -2); Here, the 2 means "sort in column 2," and the negative sign in front of the 2 means "in de -scending

How to create a simple prefix index in Java?

烈酒焚心 提交于 2019-12-18 06:45:06
问题 I have big set of urls and I want to implement an autocompletion. I don't like the complexity of the naive approach as it is linear with the set size: for(String url: urls) if(url.startsWith(input) {doSomething();} Now I know that in a Hash Set, the function "contains()" works in "O(1)" but there is no "containsPrefix()". Is there a simple way without using a big library like Lucene or coding it myself? I would have no problem doing it but it seems overkill for such a simple problem so I want

How to create a simple prefix index in Java?

情到浓时终转凉″ 提交于 2019-12-18 06:44:07
问题 I have big set of urls and I want to implement an autocompletion. I don't like the complexity of the naive approach as it is linear with the set size: for(String url: urls) if(url.startsWith(input) {doSomething();} Now I know that in a Hash Set, the function "contains()" works in "O(1)" but there is no "containsPrefix()". Is there a simple way without using a big library like Lucene or coding it myself? I would have no problem doing it but it seems overkill for such a simple problem so I want

MySQL Query does not use index in table join

扶醉桌前 提交于 2019-12-18 05:54:36
问题 I am trying to list all the book_sales information for a particular book author. So I have a query and it's not using Index to lookup records. The following is my tables structure: -- Table structure for table `books` CREATE TABLE IF NOT EXISTS `books` ( `book_id` int(11) NOT NULL auto_increment, `author_id` int(11) unsigned NOT NULL, `book_type_id` int(11) NOT NULL, `book_title` varchar(50) NOT NULL, `book_price` smallint(4) NOT NULL, `in_stock` char(1) NOT NULL, PRIMARY KEY (`book_id`), KEY

Linq to SQL nvarchar problem

馋奶兔 提交于 2019-12-18 05:48:11
问题 I have discovered a huge performance problem in Linq to SQL. When selecting from a table using strings, the parameters passed to sql server are always nvarchar, even when the sql table is a varchar. This results in table scans instead of seeks, a massive performance issue. var q = ( from a in tbl where a.index == "TEST" select a) var qa = q.ToArray(); The parameter is passed through as a nvarchar, which results in the entire index being converted from varchar to nvarchar before being used. If

Can I modify existing index in MongoDB without dropping it?

陌路散爱 提交于 2019-12-18 05:48:10
问题 Can I modify existing index in MongoDB without dropping it ? I don't see anything about it in documentation. I have an non-unique index on String field. Collection is ~6M documents. It's replica set. I know I can delete index and add new one. But it's problematic due to two reasons: 1) at time while index doesn't exist some queries will be very very slow. 2) adding new index (in my project) creates very high load on DB which visibly slows down my web-site. 回答1: There is no way to alter an

Pandas: Selecting DataFrame rows between two dates (Datetime Index)

女生的网名这么多〃 提交于 2019-12-18 05:47:18
问题 I have a Pandas DataFrame with a DatetimeIndex and one column MSE Loss the index is formatted as follows: DatetimeIndex(['2015-07-16 07:14:41', '2015-07-16 07:14:48', '2015-07-16 07:14:54', '2015-07-16 07:15:01', '2015-07-16 07:15:07', '2015-07-16 07:15:14',...] It includes several days. I want to select all the rows (all times) of a particular days without specifically knowing the actual time intervals. For example: Between 2015-07-16 07:00:00 and 2015-07-16 23:00:00 I tried the approach

get index of character in python list

倾然丶 夕夏残阳落幕 提交于 2019-12-18 05:44:45
问题 What would be the best way to find the index of a specified character in a list containing multiple characters? 回答1: >>> ['a', 'b'].index('b') 1 If the list is already sorted, you can of course do better than linear search. 回答2: Probably the index method? a = ["a", "b", "c", "d", "e"] print a.index("c") 回答3: As suggested by others, you can use index . Other than that you can use enumerate to get both the index as well as the character for position,char in enumerate(['a','b','c','d']): if char

Does SQL Server Index Null Values in a Non-Clustered Non-Unique index?

删除回忆录丶 提交于 2019-12-18 05:29:06
问题 I am considering adding a column to a database table, and that column will be null possibly for most rows however I do want to be able to query on that column for particular non-null values. Therefore an index would help with retrieval time, however if null values are included that would ruin the selectivity of my index. I have done some reading and I have got the impression that SQL Server doesn't necessarily adhere to standards when it comes to NULL values and indexes, but I can find no