Click here to Skip to main content
16,004,969 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
QuestionA particular bug-bear of mine. Pin
Pete O'Hanlon2-Jan-07 4:30
mvePete O'Hanlon2-Jan-07 4:30 
AnswerRe: A particular bug-bear of mine. Pin
J4amieC3-Jan-07 1:23
J4amieC3-Jan-07 1:23 
GeneralRe: A particular bug-bear of mine. Pin
Pete O'Hanlon3-Jan-07 3:58
mvePete O'Hanlon3-Jan-07 3:58 
AnswerRe: A particular bug-bear of mine. Pin
Ed.Poore3-Jan-07 7:09
Ed.Poore3-Jan-07 7:09 
GeneralRe: A particular bug-bear of mine. Pin
Pete O'Hanlon3-Jan-07 8:36
mvePete O'Hanlon3-Jan-07 8:36 
GeneralRe: A particular bug-bear of mine. Pin
Ed.Poore3-Jan-07 8:50
Ed.Poore3-Jan-07 8:50 
AnswerRe: A particular bug-bear of mine. Pin
Code_Doctor16-Apr-07 18:10
Code_Doctor16-Apr-07 18:10 
QuestionSelection, as if it were text. Pin
Captain See Sharp27-Dec-06 10:01
Captain See Sharp27-Dec-06 10:01 
I am attempting to create a more efficient way to select data(like text). Before I used an index to the data that was stored in an array. I would have a separate collection or array that held the indexes of the data for another array. Each index in the "selection array" was selected. I think I have made a more efficient way to do that using two longs per selection, it does not matter how large the selection is, it will always be two longs. You can select multiple items. I'm using this in a application that can select data just like in notepad or a hex editor.

void SelectData(long start, long end)
{
  _selected.Add(new Range(start, end));
  if (_selected.Count > 1)
    RemoveRangeRedundancies();
}

void RemoveRangeRedundancies()
{
  foreach (Range rr in _selected)
  {
    foreach (Range r in _selected)
    {
      if (rr == r) continue;

      if (rr.MinValue >= r.MinValue && rr.MaxValue <= r.MaxValue)  //selection completely inside an already selected range of data.
      {
        _selected.Remove(rr);
        continue;
      }

      if (rr.MinValue <= r.MinValue && rr.MaxValue >= r.MaxValue) //selection bigger on both or one rr.MaxValue
      {
        _selected.Remove(r);
        continue;
      }

      //selection bigger or connected to the left (join)
      if (rr.MinValue < r.MinValue && (rr.MaxValue >= r.MinValue - 1) && rr.MaxValue <= r.MaxValue)
      {
        Range newRange = new Range(rr.MinValue, r.MaxValue);
        _selected.Remove(rr);
        _selected.Remove(r);
        _selected.Add(newRange);
        continue;
      }

      //selection bigger or connected to the right (join)
      if (rr.MinValue >= r.MinValue && (rr.MinValue <= r.MaxValue + 1) && rr.MaxValue > r.MaxValue)
      {
        Range newRange = new Range(r.MinValue, rr.MaxValue);
        _selected.Remove(rr);
        _selected.Remove(r);
        _selected.Add(newRange);
        continue;
      }
    }
  }
}



Do you think that is a good design?


█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██

AnswerRe: Selection, as if it were text. Pin
J. Dunlap28-Dec-06 1:37
J. Dunlap28-Dec-06 1:37 
GeneralRe: Selection, as if it were text. Pin
Captain See Sharp28-Dec-06 8:51
Captain See Sharp28-Dec-06 8:51 
GeneralRe: Selection, as if it were text. Pin
J. Dunlap28-Dec-06 14:58
J. Dunlap28-Dec-06 14:58 
GeneralRe: Selection, as if it were text. Pin
Captain See Sharp28-Dec-06 15:33
Captain See Sharp28-Dec-06 15:33 
GeneralRe: Selection, as if it were text. [modified][modified] Pin
Captain See Sharp3-Jan-07 13:33
Captain See Sharp3-Jan-07 13:33 
QuestionNew Forum Pin
Bradml25-Dec-06 0:13
Bradml25-Dec-06 0:13 
GeneralAwesome! Pin
J. Dunlap24-Dec-06 14:51
J. Dunlap24-Dec-06 14:51 
GeneralFirst Square Post On A New Forum Pin
Bassam Abdul-Baki23-Dec-06 9:04
professionalBassam Abdul-Baki23-Dec-06 9:04 
JokeWhy Discriminate? Pin
CPallini23-Dec-06 23:31
mveCPallini23-Dec-06 23:31 
GeneralRe: First Square Post On A New Forum Pin
Paul Conrad26-Dec-06 18:24
professionalPaul Conrad26-Dec-06 18:24 
GeneralRe: First Square Post On A New Forum Pin
User 171649227-Dec-06 1:52
professionalUser 171649227-Dec-06 1:52 
GeneralRe: First Square Post On A New Forum Pin
Paul Conrad27-Dec-06 6:11
professionalPaul Conrad27-Dec-06 6:11 
GeneralRe: First Square Post On A New Forum Pin
Bassam Abdul-Baki27-Dec-06 7:26
professionalBassam Abdul-Baki27-Dec-06 7:26 
GeneralRe: First Square Post On A New Forum Pin
Paul Conrad27-Dec-06 7:45
professionalPaul Conrad27-Dec-06 7:45 
GeneralRe: First Square Post On A New Forum Pin
Bassam Abdul-Baki27-Dec-06 9:44
professionalBassam Abdul-Baki27-Dec-06 9:44 
GeneralRe: First Square Post On A New Forum Pin
Paul Conrad27-Dec-06 10:11
professionalPaul Conrad27-Dec-06 10:11 
GeneralRe: First Square Post On A New Forum Pin
User 171649227-Dec-06 12:57
professionalUser 171649227-Dec-06 12:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.