|
1. The lounge is for the CodeProject community to discuss things of interest to the community, and as a place for the whole community to participate. It is, first and foremost, a respectful meeting and discussion area for those wishing to discuss the life of a Software developer.
The #1 rule is: Be respectful of others, of the site, and of the community as a whole.
2. Technical discussions are welcome, but if you need specific programming question answered please use Quick Answers[^], or to discussion your programming problem in depth use the programming forums[^]. We encourage technical discussion, but this is a general discussion forum, not a programming Q&A forum. Posts will be moved or deleted if they fit better elsewhere.
3. No sys-admin, networking, "how do I setup XYZ" questions. For those use the SysAdmin[^] or Hardware and Devices[^] forums.
4. No politics (including enviro-politics[^]), no sex, no religion. This is a community for software development. There are plenty of other sites that are far more appropriate for these discussions.
5. Nothing Not Safe For Work, nothing you would not want your wife/husband, your girlfriend/boyfriend, your mother or your kid sister seeing on your screen.
6. Any personal attacks, any spam, any advertising, any trolling, or any abuse of the rules will result in your account being removed.
7. Not everyone's first language is English. Be understanding.
Please respect the community and respect each other. We are of many cultures so remember that. Don't assume others understand you are joking, don't belittle anyone for taking offense or being thin skinned.
We are a community for software developers. Leave the egos at the door.
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
modified 16-Sep-19 9:31am.
|
|
|
|
|
Mine has to be inserts and deletions in containers implemented over arrays:
Below is some ugly code. I hate this. B-trees are FAR worse though.
bool ICollection<T>.Remove(T item)
{
if (Equals(_array[_head],item))
{
Dequeue();
return true;
}
else
{
for(var i = 0;i<_count;++i)
{
var idx = (_head + i) % _array.Length;
if(Equals(_array[idx],item))
{
if (_head + _count < _array.Length)
{
Array.Copy(_array, idx + 1, _array, idx, _count - idx - 1);
}
else if (idx == _array.Length - 1)
{
_array[idx] = _array[0];
if(_count+_head!=_array.Length)
{
Array.Copy(_array, 1, _array, 0, (_count + _head) % _array.Length - 1);
}
}
else if (idx < _head)
{
Array.Copy(_array, idx + 1, _array, idx, (_count + _head) % _array.Length - 1);
}
--_count;
unchecked
{
++_version;
}
return true;
}
}
}
return false;
}
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I can feel the lack of love in ya code...
you can do nicer, I believe in ya!
Also there is a bug!
If T is a reference type, you would leave the reference at the head index being duplicated (and NOT garbage collected)... you should set newly empty spot to default(T)
as in, if you remove B
your underlying array will go from
A | B | C
to
A | C | C
The last C will prevent garbage collection of C
|
|
|
|
|
yeah that's true. I wasn't considering the collection of ref types there. Now I can see why microsoft cleared their arrays. I didn't put 2 and 2 together and think about garbage collection. meh. thanks.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Here you go corrected version.. though I feel I might be wrong a little bit by +/- 1 on some indexes, you gotta proof read it!
EDIT (oops got the count wrong on my removes... buut I still hope the general outline ispire you for its simplicity! )
v1
bool ICollection<T>.Remove(T item)
{
for(var i = 0; i < _count; ++i)
{
var idx = (_head + i) % _array.Length;
if(!Equals(_array[idx],item))
continue;
if (_head + _count < _array.Length)
{
Array.Copy(_array, idx + 1, _array, idx, _count - idx - 1);
}
else if (idx < _head)
{
Array.Copy(_array, idx + 1, _array, idx, ((_head + _count) % _array.Length - idx - 1));
}
else
{
Array.Copy(_array, idx + 1, _array, idx, _array.Length - idx - 1);
_array[_array.Length - 1] = _array[0];
Array.Copy(_array, 1, _array, 0, _head - 1);
}
_array[_head + _count - 1] = default(T);
--_count;
unchecked { ++_version; }
return true;
}
return false;
}
v2
bool ICollection<T>.Remove(T item)
{
var i = FindIndex(item);
if (i == -1)
return false;
var idx = (_head + i) % _array.Length;
if (_head + _count < _array.Length)
{
Array.Copy(_array, idx + 1, _array, idx, _count - idx - 1);
}
else if (idx < _head)
{
Array.Copy(_array, idx + 1, _array, idx, (_head - idx - 1));
}
else
{
Array.Copy(_array, idx + 1, _array, idx, _array.Length - idx - 1);
_array[_array.Length - 1] = _array[0];
Array.Copy(_array, 1, _array, 0, _head - 1);
}
_array[_head + _count - 1] = default(T);
--_count;
unchecked { ++_version; }
return true;
}
modified 1hr ago.
|
|
|
|
|
|
No?
Why should it in your mind?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
This question, Googled, returns 108 hits which ALL have nothing to do with what is implicit to it, as a question. So, yeah, I guess "No" is really the most useful thing anyone would expect to gain by typing the question, or any question for that matter, into that pile of ... nonsense.
So thanks for this.
|
|
|
|
|
This is a good example of the hidden esoteric teaching (gematria) behind Google's search engine.
I am not allowed to say too much, but, note that 108 is a sacred number in Buddhism, and Hinduism, Sikh religion, and Jainism ... it also happens to be the hyperfactorial of 3 : sum of two squared and three cubed. Each interior angle of a pentagon is 108.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
And it works!
Every time I turn off my monitor it goes black! (and it can go back! )
|
|
|
|
|
bring back the CRT, cats have nowhere to sit on them LCD's
|
|
|
|
|
|
The longer middle finger in the stop sign must have been the first clue. 
|
|
|
|
|
This could be the plot for a Coen brothers' film.
/ravi
|
|
|
|
|
He made quite a lot of money out of it, proving that walls work.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I would recommend my old Elf's keyboard[^]. Steel case, real key switches and lasts at least 42 years long.
But parallel keyboards of that sort don't grow on trees these days and I will need something more modern when I build 'Zwölf', Elf's younger brother. Just yesterday I was asking dumb questions about interfacing USB ports to an 8 bit computer, guess why.
But there is another way to get exactly the keyboard that you want and that lasts forever.
Tear out the encoder and the cable from an old keyboard. Then buy about a pound of cherry keyswitches[^]. Then design and 3D print keycaps and a case for the keyboard[^]. Layout, spacing and finish are entirely up to you.
You will not need a circuit board. The keyswitches snap into square holes in the case, but you will have to wire up the switches in columns and rows on the underside and then also connect the encoder you have salvaged from an old keyboard.
I might have to do a little more, like programming a PIC microcontroller with a suitable interface as keyboard encoder, but that's worth it. That keyboard can last another 42 years.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Good idea, switches are cheap enough.
They call me different but the truth is they're all the same!
JaxCoder.com
|
|
|
|
|
|
Ahhh, steampunk! Hook that thing up to an Elf with Nixie Tubes[^] for the data and address displays.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Was de-bounce technology common in those days, or was that offered as an upgrade?
/ravi
|
|
|
|
|
Very common. In hardware, not in software as it is done now. Tantalum capacitors, to be precise.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Why not buy a Cherry keyboard?
|
|
|
|
|
I heard they are especially good for cherry-picking with Git 
|
|
|
|
|
RickZeeland wrote: Git Gaah! Someone hand me a barf bag.
/ravi
|
|
|
|
|
You're doing it again, Ravi. Just wait until the zealots come out. 
|
|
|
|
|