Results 1 to 8 of 8

Thread: Help me to get a decision (dictionary)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Help me to get a decision (dictionary)

    Quote Originally Posted by jmcilhinney View Post
    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).
    Last edited by mitko29; Jul 25th, 2012 at 03:33 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Help me to get a decision (dictionary)

    Quote Originally Posted by jmcilhinney View Post
    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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Help me to get a decision (dictionary)

    Quote Originally Posted by jmcilhinney View Post
    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 ?

  7. #7
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    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
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Help me to get a decision (dictionary)

    Quote Originally Posted by Lightning View Post
    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
  •  



Click Here to Expand Forum to Full Width