Article View: comp.lang.c
Article #1585Re: Inversion-of-control and dependency-injection in C
From: fir
Date: Mon, 16 Nov 2026 18:08
Date: Mon, 16 Nov 2026 18:08
69 lines
3933 bytes
3933 bytes
fir pisze:
> so maybe try it right c way
>
>
>
>
> typedef unsigned int UI32;
>
> UI32 * RadixSortUnsigned(UI32 * pData, UI32 * pTemp, size_t count)
> {
> size_t mIndex[4][256] = {0}; // index matrix
> UI32 *pDst, *pSrc, *pTmp;
> size_t i,j,m,n;
> UI32 u;
>
> for(i = 0; i < count; i++){ // generate histograms
> u = pData[i];
> for(j = 0; j < 4; j++){
> mIndex[j][(size_t)(u & 0xff)]++;
> u >>= 8;
> }
> }
> for(j = 0; j < 4; j++){ // convert to indices
> n = 0;
> for(i = 0; i < 256; i++){
> m = mIndex[j][i];
> mIndex[j][i] = n;
> n += m;
> }
> }
> pDst = pTemp; // radix sort
> pSrc = pData;
> for(j = 0; j < 4; j++){
> for(i = 0; i < count; i++){
> u = pSrc[i];
> m = (size_t)(u >> (j<<3)) & 0xff;
> pDst[mIndex[j][m]++] = u;
> }
> pTmp = pSrc;
> pSrc = pDst;
> pDst = pTmp;
> }
> return(pSrc);
> }
>
>
not i took this from the net so its not my own code and when i took it i
dont understood it (i only knew that radix sort may be nbetter and
std sort form c++ is suposingly lame)..so i measured it 27 ms C vs 111
ms stdlib C++ ;c
now i understand it its not so hard first you build histograms for each
byte of input (if input is 1M you got 4M ++s
then you transform this histogram into offsets like 0:17 1:32 turns into
0 17 49...
then you travel on oryginal input array and use those offsets as movabe
i mean if you find byte "2" you put it in tab[49]="this number that lasy
byte is 2" and increase 49 on 50 on next pass you do it on 2nd byte
so its 4x1MB insertions
its quite neat and i dont see it yet maybe totally sharop but a abit of
focus and it can be quite sharply understood (i understand it enough)
overally it is quite C style algortihm much more than typical sorting
so it not only beats those sortings but is indeed C style
Technical Details
Message-ID:
<11dfgqa$3ph69$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com> <11d54jb$80v7$1@raubtier-asyl.eternal-september.org> <11d56pj$8sfe$1@dont-email.me> <11df75b$3lnf4$1@raubtier-asyl.eternal-september.org> <11df7h3$3lpoh$1@dont-email.me> <11dfb43$3n757$1@raubtier-asyl.eternal-september.org> <11dfcqi$3ntok$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: Inversion-of-control and dependency-injection in C Date: Mon, 16 Nov 2026 19:08:10 +0100 Organization: A noiseless patient Spider Lines: 69 Message-ID: <11dfgqa$3ph69$1@dont-email.me> References: <yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com> <11d54jb$80v7$1@raubtier-asyl.eternal-september.org> <11d56pj$8sfe$1@dont-email.me> <11df75b$3lnf4$1@raubtier-asyl.eternal-september.org> <11df7h3$3lpoh$1@dont-email.me> <11dfb43$3n757$1@raubtier-asyl.eternal-september.org> <11dfcqi$3ntok$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 16 Nov 2026 18:08:11 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3982537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sSvPUZ8lM586VLD2BQMUq8zIPJ/5bEPE="; posting-host="ffaeb1a4357f66637402e7443ff79a2b" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:Ze8kR+m1eJu3Z7GsGl1xEdHpK00= sha256:37xltVsvqGrHpTLcrkkF0XD/2lJsFoN6Z3JuexsPrrA= sha1:X/3lODMF7N/jpXtx3xIZQ289EiU= sha256:TvsrJQn/y2QzcE1xbTolp8cEkB49a8cYVt2iIitubm0= In-Reply-To: <11dfcqi$3ntok$1@dont-email.me>