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. :eek: 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 :)
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?
Re: Help me to get a decision (dictionary)
Quote:
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 :)
Quote:
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).
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?
Re: Help me to get a decision (dictionary)
Quote:
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 :)
Re: Help me to get a decision (dictionary)
Quote:
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 ?
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
Re: Help me to get a decision (dictionary)
Quote:
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 :)