Sorted List Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Zurer

    #1

    Sorted List Problem

    Assuming that I have created a strongly typed collection and overridden the
    appropriate methods, i.e. this[], Add, Insert etc., so that a sort order is
    maintained, it's still very possible for a property of the
    'ListMemberObje ct' which is instrumental in the sort to be modified
    unbeknownst to the list thereby defeating the sort.

    One way to keep the list sorted is to add a 'ParentList' property to the
    ListMemberObjec t and notify that ParentList to sort itself in every set
    method of the list object. That would repeat code everywhere and is
    extremely yucky.

    I've looked at a few implementations of creating a sorted list, most notably



    but the problem is not addressed.

    In a related vein. If I want to use ArrayList.Binar ySearch for the express
    purpose of only adding unique values,

    public override int Add(object o)
    {
    int result = -1;
    if(o == null)throw new ArgumentNullExc eption();
    IComparer idComparer = new IDComparer();

    Sort(idComparer );
    //if I call this here the application dies a slow and painful death with
    a large list
    //if I don't call it I'm not absolutely sure my list is sorted properly

    int binSrch = this.BinarySear ch(idComparer );
    if(binSrch < 0)
    {
    base.Insert(~bi nSrch, o);
    result = ~binSrch;
    }
    return result;
    }

    What to do?


    TIA

    Robert Zurer



  • Horatiu Ripa

    #2
    Re: Sorted List Problem

    Why didn't you implement a binary tree (ordered)? Well implemented all your
    troubles will dissapear.
    --
    Horatiu Ripa

    "Robert Zurer" <robert@zurer.c om> wrote in message
    news:uBFB9dzdDH A.1884@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Assuming that I have created a strongly typed collection and overridden[/color]
    the[color=blue]
    > appropriate methods, i.e. this[], Add, Insert etc., so that a sort order[/color]
    is[color=blue]
    > maintained, it's still very possible for a property of the
    > 'ListMemberObje ct' which is instrumental in the sort to be modified
    > unbeknownst to the list thereby defeating the sort.
    >
    > One way to keep the list sorted is to add a 'ParentList' property to the
    > ListMemberObjec t and notify that ParentList to sort itself in every set
    > method of the list object. That would repeat code everywhere and is
    > extremely yucky.
    >
    > I've looked at a few implementations of creating a sorted list, most[/color]
    notably[color=blue]
    >
    > http://www.codeproject.com/useritems/SortableList.asp
    >
    > but the problem is not addressed.
    >
    > In a related vein. If I want to use ArrayList.Binar ySearch for the express
    > purpose of only adding unique values,
    >
    > public override int Add(object o)
    > {
    > int result = -1;
    > if(o == null)throw new ArgumentNullExc eption();
    > IComparer idComparer = new IDComparer();
    >
    > Sort(idComparer );
    > //if I call this here the application dies a slow and painful death[/color]
    with[color=blue]
    > a large list
    > //if I don't call it I'm not absolutely sure my list is sorted[/color]
    properly[color=blue]
    >
    > int binSrch = this.BinarySear ch(idComparer );
    > if(binSrch < 0)
    > {
    > base.Insert(~bi nSrch, o);
    > result = ~binSrch;
    > }
    > return result;
    > }
    >
    > What to do?
    >
    >
    > TIA
    >
    > Robert Zurer
    >
    >
    >[/color]


    Comment

    • Robert Zurer

      #3
      Re: Sorted List Problem

      Thanks for the suggestion, do you have any links to a good implementation? ?


      Robert Zurer


      "Horatiu Ripa" <horatiu.ripa@b usinesslogic.co .uk> wrote in message
      news:u9UFmI5dDH A.3228@tk2msftn gp13.phx.gbl...[color=blue]
      > Why didn't you implement a binary tree (ordered)? Well implemented all[/color]
      your[color=blue]
      > troubles will dissapear.
      > --[/color]


      Comment

      • Horatiu Ripa

        #4
        Re: Sorted List Problem

        try


        You don't have to use that implementation but it gives you an idea.

        --
        Horatiu Ripa
        Software Development Manager
        Business Logic Systems LTD
        21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
        Phone/Fax: +40 264 590703
        Web: www.businesslogic.co.uk

        This email (email message and any attachments) is strictly confidential,
        possibly privileged and is intended solely for the person or organization to
        whom it is addressed. If you are not the intended recipient, you must not
        copy, distribute or take any action in reliance on it. If you have received
        this email in error, please inform the sender immediately before deleting
        it. Business Logic Systems Ltd accepts no responsibility for any advice,
        opinion, conclusion or other information contained in this email or arising
        from its disclosure.

        "Robert Zurer" <robert@zurer.c om> wrote in message
        news:uAXrWh5dDH A.3948@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Thanks for the suggestion, do you have any links to a good[/color]
        implementation? ?[color=blue]
        >
        >
        > Robert Zurer
        >
        >
        > "Horatiu Ripa" <horatiu.ripa@b usinesslogic.co .uk> wrote in message
        > news:u9UFmI5dDH A.3228@tk2msftn gp13.phx.gbl...[color=green]
        > > Why didn't you implement a binary tree (ordered)? Well implemented all[/color]
        > your[color=green]
        > > troubles will dissapear.
        > > --[/color]
        >
        >[/color]


        Comment

        • Horatiu Ripa

          #5
          Re: Sorted List Problem

          The add, search, getnext methods are trivial to implement - recursively -
          and you can get them from there.
          But the remove function is tricky and quite nice, and not implemented
          there!!!

          --
          Horatiu Ripa
          Software Development Manager
          Business Logic Systems LTD
          21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
          Phone/Fax: +40 264 590703
          Web: www.businesslogic.co.uk

          This email (email message and any attachments) is strictly confidential,
          possibly privileged and is intended solely for the person or organization to
          whom it is addressed. If you are not the intended recipient, you must not
          copy, distribute or take any action in reliance on it. If you have received
          this email in error, please inform the sender immediately before deleting
          it. Business Logic Systems Ltd accepts no responsibility for any advice,
          opinion, conclusion or other information contained in this email or arising
          from its disclosure.

          "Robert Zurer" <robert@zurer.c om> wrote in message
          news:uAXrWh5dDH A.3948@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Thanks for the suggestion, do you have any links to a good[/color]
          implementation? ?[color=blue]
          >
          >
          > Robert Zurer
          >
          >
          > "Horatiu Ripa" <horatiu.ripa@b usinesslogic.co .uk> wrote in message
          > news:u9UFmI5dDH A.3228@tk2msftn gp13.phx.gbl...[color=green]
          > > Why didn't you implement a binary tree (ordered)? Well implemented all[/color]
          > your[color=green]
          > > troubles will dissapear.
          > > --[/color]
          >
          >[/color]


          Comment

          Working...