|
-
Jul 24th, 2012, 11:27 AM
#1
Thread Starter
Addicted Member
Help me to get a decision (dictionary)
Hello, guys I found one interesting task in one of my programming book which I coulddn't solve there and I am trying to do it now.
So in this task I have three field Name,Product,Price and I can have dublicated item, so I have to evade this too,but on the other hand in the structure of data I will chose later I have to save up to 100 050 records, and search threw them for over 2,50 sec. and I can use only the .NET framework and nothing custom.
So if I chose dictionary or sortedDictionary I have to enter Key & Value , but I can't dublicate item there and if I use KeyValuePair I will have something like this :
Dictionary<KeyValuePairs<Name,Producer>,Price> shopDB;
But then how to add element, search fast in this dictionary and delete item from KeyValuePairs ?
Can you give me some advice how to solve this
Last edited by mitko29; Jul 25th, 2012 at 03:31 AM.
-
Jul 24th, 2012, 09:42 PM
#2
Re: Help me to get a decision (dictionary)
To be clear, you can have duplicate Name values and you can have duplicate Product values but you cannot have duplicate combinations of Name and Product, correct?
-
Jul 25th, 2012, 03:30 AM
#3
Thread Starter
Addicted Member
Re: Help me to get a decision (dictionary)
 Originally Posted by jmcilhinney
To be clear, you can have duplicate Name values and you can have duplicate Product values but you cannot have duplicate combinations of Name and Product, correct?
No, I can have dublicate combinations of Name and Product 
 Originally Posted by task
adds a product by given name, price and producer. If a product with the same name / producer/ price already exists, the newly added product does not affect the existing ones (duplicates are allowed).
Last edited by mitko29; Jul 25th, 2012 at 03:33 AM.
-
Jul 25th, 2012, 05:14 AM
#4
Re: Help me to get a decision (dictionary)
What do you want to be able to search by, each field individually or some specific combination?
-
Jul 25th, 2012, 06:45 AM
#5
Thread Starter
Addicted Member
Re: Help me to get a decision (dictionary)
 Originally Posted by jmcilhinney
What do you want to be able to search by, each field individually or some specific combination?
Well acording to the program I have to add Name,Price,Producer which is my class Products.
Then I have to delete by name or by name and producer.
Search by all items by name , and all items by producer and in the end search by price range
-
Jul 25th, 2012, 03:24 PM
#6
Thread Starter
Addicted Member
Re: Help me to get a decision (dictionary)
 Originally Posted by jmcilhinney
What do you want to be able to search by, each field individually or some specific combination?
Can you point me how to solve it ?
-
Jul 31st, 2012, 03:04 PM
#7
Re: Help me to get a decision (dictionary)
I would use a create a class:
Code:
public class Product
{
public string name{ get; set;}
public double price {get; set;}
public string product {get; set;}
}
Then create a list of those class:
Code:
List<Product> productList = new List<Product>();
Then you have full control. You can search very fast, if you include the system.linq namespace. You can search using:
Code:
product = productList.First(p => p.name == "TestName");
This should be enough information (maybe too much) to get started
-
Jul 31st, 2012, 04:40 PM
#8
Thread Starter
Addicted Member
Re: Help me to get a decision (dictionary)
 Originally Posted by Lightning
I would use a create a class:
Code:
public class Product
{
public string name{ get; set;}
public double price {get; set;}
public string product {get; set;}
}
Then create a list of those class:
Code:
List<Product> productList = new List<Product>();
Then you have full control. You can search very fast, if you include the system.linq namespace. You can search using:
Code:
product = productList.First(p => p.name == "TestName");
This should be enough information (maybe too much) to get started
Using list is maybe the worst idea here,search and order them I have to go threw every element in the list and this is hell slow and the program have to work for under 2 seconds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|