473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bit testing

Hi all, hope someone can help me with an algorithm.

I have a bitmap representing available pages in a file. A
GetPage(PageCount) function should return the offset into the file where
PageCount of contiguous pages resides. Within the function I have a pointer
to the bitmap and want to scan the bitmap until PageCount of free bits is
found. For example assume the following bitmap is present in memory:

10101100110001101010000111111011001011001

If I wanted to retrieve the offset where 4 bits are free, the
FindFreeBitsInBitmap(4) function should return 18 (the location of 0000)

My FindFreeBitsInBitmap(BitCount) function should scan the block of memory
until it encounters BitCount of free bits. Then should return the offset
into the block where the free bits occur. There's several approaches to
this problem, can someone provide me with a very efficient algorithm to
locate the starting offset? This function resides in a DBMS and should be
very efficient as it's called very frequently. An assembler routine is also
an option. All input is greatly appreciated.

Cheers,
David
Jul 22 '05 #1
12 1493
David Mott wrote:
Hi all, hope someone can help me with an algorithm.

I have a bitmap representing available pages in a file. A
GetPage(PageCount) function should return the offset into the file where
PageCount of contiguous pages resides. Within the function I have a pointer
to the bitmap and want to scan the bitmap until PageCount of free bits is
found. For example assume the following bitmap is present in memory:

10101100110001101010000111111011001011001

If I wanted to retrieve the offset where 4 bits are free, the
FindFreeBitsInBitmap(4) function should return 18 (the location of 0000)

My FindFreeBitsInBitmap(BitCount) function should scan the block of memory
until it encounters BitCount of free bits. Then should return the offset
into the block where the free bits occur. There's several approaches to
this problem, can someone provide me with a very efficient algorithm to
locate the starting offset? This function resides in a DBMS and should be
very efficient as it's called very frequently. An assembler routine is also
an option. All input is greatly appreciated.


This is off-topic on comp.lang.c++ since there is nothing specific in
your question about C++ - try comp.programming or an algorithms group.

Jul 22 '05 #2


"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:bu********@dispatch.concentric.net...
David Mott wrote:
Hi all, hope someone can help me with an algorithm.

I have a bitmap representing available pages in a file. A
GetPage(PageCount) function should return the offset into the file where
PageCount of contiguous pages resides. Within the function I have a pointer to the bitmap and want to scan the bitmap until PageCount of free bits is found. For example assume the following bitmap is present in memory:

10101100110001101010000111111011001011001

If I wanted to retrieve the offset where 4 bits are free, the
FindFreeBitsInBitmap(4) function should return 18 (the location of 0000)

My FindFreeBitsInBitmap(BitCount) function should scan the block of memory until it encounters BitCount of free bits. Then should return the offset into the block where the free bits occur. There's several approaches to
this problem, can someone provide me with a very efficient algorithm to
locate the starting offset? This function resides in a DBMS and should be very efficient as it's called very frequently. An assembler routine is also an option. All input is greatly appreciated.


This is off-topic on comp.lang.c++ since there is nothing specific in
your question about C++ - try comp.programming or an algorithms group.


Idiot, of course it's not C++ exclusive, the algorithm could be of any type,
C++ included. If you have a c/c++ algorithm, then post it. If not, don't
be a stupid ass and keep quiet.

Jul 22 '05 #3
"David Mott" <dm***@austin.rr.not.home.com> wrote in message
news:Qc*****************@fe1.texas.rr.com...

"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:bu********@dispatch.concentric.net...
David Mott wrote:

This is off-topic on comp.lang.c++ since there is nothing specific in your question about C++ - try comp.programming or an algorithms
group.
Idiot, of course it's not C++ exclusive, the algorithm could be of any type, C++ included. If you have a c/c++ algorithm, then post it. If not, don't be a stupid ass and keep quiet.


It may not be off topic, but do you really expect anyone to answer
your question now?

Jonathan
Jul 22 '05 #4
David Mott wrote:
"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:bu********@dispatch.concentric.net...
David Mott wrote:
Hi all, hope someone can help me with an algorithm.
.... Idiot, of course it's not C++ exclusive, the algorithm could be of any type,
C++ included. If you have a c/c++ algorithm, then post it. If not, don't
be a stupid ass and keep quiet.


Let's see - you ask for help, I offer some help, you start name calling

.... OK let's try again.

It really is off topic in this NG. This NG is about questions on the
standard and yeah, sometimes people are nice and they pitch in for off
topic questions but in your case the question is about performance and
algorithms and nothing specifically to do with C++. You also ask for
assembler options which begs the question - which ISA which you leave
unanswered.

There is no doubt that this is a solved problem, file systems (hint -
linux kernel) use bitmaps as well and there are some really good
resources in filesystems code (like find first set and find last set
assembler code for numerous architectures).

I'm sorry you took the tone of my answer to be other than what it was,
an attempt at being helpful; I truly meant it in the politest way possible.

Chill a little, go write some code, come back with some questions on
your C++ problems and I'm sure you'll find many willing helpers that
will do their best for you.
Jul 22 '05 #5
On 23 Jan 2004 02:29:37 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
It really is off topic in this NG. This NG is about questions on the
standard and yeah, sometimes people are nice and they pitch in for off
topic questions but in your case the question is about performance and
algorithms and nothing specifically to do with C++.


No, it isn't. You totally miss the point. Let us assume that
performance of the algorithm is not actually the issue here. How would
you code the answer in C++? Use the simplest algorithm that comes to
mind, and show the poor fellow some way to approach the problem in C++.
Now that you have made such a big deal over it, that was obviously the
way to interpret the question all along, merely by the fact that it is
posted here.

So now is the time for you to put up some code.

Jul 22 '05 #6
David Harmon wrote:
On 23 Jan 2004 02:29:37 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
It really is off topic in this NG. This NG is about questions on the
standard and yeah, sometimes people are nice and they pitch in for off
topic questions but in your case the question is about performance and
algorithms and nothing specifically to do with C++.

No, it isn't. You totally miss the point. Let us assume that
performance of the algorithm is not actually the issue here. How would
you code the answer in C++?


I think you'll find that is not the case.

Karl writes :"Here we discuss only thing(s) which are defined in
Standard C++ (The language as described by the ISO document)."

Look up the FAQ, it states it more clearly.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Use the simplest algorithm that comes to mind, and show the poor fellow some way to approach the problem in C++.
I think the OP wanted the highest performance algorithm. (not that that
changes my position, it's still OT even without that requirement.)
Now that you have made such a big deal over it, that was obviously the
way to interpret the question all along, merely by the fact that it is
posted here.
I don't think it's a "big deal". All I'm trying to do is give some
helpful suggestions. No skin off my nose if the OP or yourself don't
wish to take it - that's entirely up to you. I think I speak for most
of the people who regularly help on c.l.c++ in saying that this question
is OT.

So now is the time for you to put up some code.


If I wanted to, I would have done that already. I've already given the
best advice I can with my available time. If you take this question to
comp.programming or a better suited NG I honestly think you'll find
better answers.

BTW - I'm probably the worst offender of "answering off-topic questions"
in c.l.c++ (look at the next post -Subj: C vs C++ in pthreads- for
evidence). So when I say it's off topic, I'm usually right by a wide
margin...

Peace ... G

Jul 22 '05 #7

"Gianni Mariani" <gi*******@mariani.ws> wrote
David Harmon wrote:
On 23 Jan 2004 02:29:37 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
It really is off topic in this NG. This NG is about questions on the
standard and yeah, sometimes people are nice and they pitch in for off
topic questions but in your case the question is about performance and
algorithms and nothing specifically to do with C++.

No, it isn't. You totally miss the point. Let us assume that
performance of the algorithm is not actually the issue here. How would
you code the answer in C++?


I think you'll find that is not the case.

Karl writes :"Here we discuss only thing(s) which are defined in
Standard C++ (The language as described by the ISO document)."

Look up the FAQ, it states it more clearly.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9


Who is Karl? I don't care about Karl, nor take direction from him. He
hasnt helped me with an implementation. If Karl is the moderator of this
group, he should be moderating and remove the message before its posted to
the group.

Use the simplest algorithm that comes to
mind, and show the poor fellow some way to approach the problem in C++.
I think the OP wanted the highest performance algorithm. (not that that
changes my position, it's still OT even without that requirement.)


High performance is good, however, anything is better than nothing. If you
wanted to help, why not forward the post to the other group yourself? It
certainly would have saved your limited time.
Now that you have made such a big deal over it, that was obviously the
way to interpret the question all along, merely by the fact that it is
posted here.


I don't think it's a "big deal". All I'm trying to do is give some
helpful suggestions. No skin off my nose if the OP or yourself don't
wish to take it - that's entirely up to you. I think I speak for most
of the people who regularly help on c.l.c++ in saying that this question
is OT.


Yes, its no big deal, sence its no big deal, why defend your post twice? No
big deal, but your suggestion was not helpful. If the goal was to give a
helpful suggestion, you failed. I'm not seeking direction on where to post
my question. I'm sure members of this group are qualified to answer it.
Dont take the responsibility for speaking for anyone but yourself. To
defend your post, you reference Karl and "most of the people" in this NG.
Is this the case? Have you been authorized to speak in their behalf?

So now is the time for you to put up some code.


If I wanted to, I would have done that already. I've already given the
best advice I can with my available time. If you take this question to
comp.programming or a better suited NG I honestly think you'll find
better answers.


You seem to have enough time to complain, why not use your time more
constructively?
BTW - I'm probably the worst offender of "answering off-topic questions"
in c.l.c++ (look at the next post -Subj: C vs C++ in pthreads- for
evidence). So when I say it's off topic, I'm usually right by a wide
margin...


If you are the worst offender, why was my post such an offense? What's the
point? I've heard people complain about posting to threads off topic, not
to groups. On rare occasion someone will complain about spam porn hitting
the NG. It's a matter of opinion as to whether the question was off topic
or not. The NG is as much my resource as anyone else's. If you are
bothered by off topic posts, then simply ignore them, your help wasn't help
at all, it was an insult. My post could be very much on-topic depending on
how you approach it.

I have several solutions to this problem, I'm looking for suggestions and/or
implementation details, not schooling on how or where to post my question.
If you cant answer it, simply ignore it.
Jul 22 '05 #8

"David Mott" <dm***@austin.rr.not.home.com> wrote in message
news:Jy*****************@fe2.texas.rr.com...

"Gianni Mariani" <gi*******@mariani.ws> wrote
David Harmon wrote:
....
I have several solutions to this problem, I'm looking for suggestions and/or implementation details, not schooling on how or where to post my question.
If you cant answer it, simply ignore it.


Then post them and ask specific C++ questions about them. Perhaps some will
overlook your unprovoked rudeness and help you.

Jeff F
Jul 22 '05 #9
David Mott wrote:
"Gianni Mariani" <gi*******@mariani.ws> wrote ....
Who is Karl? I don't care about Karl, nor take direction from him. He
hasnt helped me with an implementation. If Karl is the moderator of this
group, he should be moderating and remove the message before its posted to
the group.
Who cares - do some research if you care so much... Google it and
you'll find it. You seem to have a phobia of researching things for
yourself.

Use the simplest algorithm that comes to
mind, and show the poor fellow some way to approach the problem in C++.
I think the OP wanted the highest performance algorithm. (not that that
changes my position, it's still OT even without that requirement.)

High performance is good, however, anything is better than nothing. If you
wanted to help, why not forward the post to the other group yourself? It
certainly would have saved your limited time.


Because it's not my problem - I have plenty of my own. Take the time to
do some more research work - or pay someone to do it.

....
I don't think it's a "big deal". All I'm trying to do is give some
helpful suggestions. No skin off my nose if the OP or yourself don't
wish to take it - that's entirely up to you. I think I speak for most
of the people who regularly help on c.l.c++ in saying that this question
is OT.

Yes, its no big deal, sence its no big deal, why defend your post twice?


Because I'm still trying to help you - this time with the best way to
use this resource. Admitedly, I'm starting to think it's a lost cause.

No big deal, but your suggestion was not helpful.
Oh well, hopefully someone else might get the benefit.

If the goal was to give a helpful suggestion, you failed.
Some people are incapable of being helped by me. Nothing I can do about
that.

I'm not seeking direction on where to post my question. I'm sure members of this group are qualified to answer it.
I don't think so. Yes, any programmer with enough experience could
probably come up with an algorithm, but not one which is going to be as
good as someone who implemented it before. As I suggested before,
kernels (mostly implemented in C) are places where these kinds of
algorithms are found. Many new file systems don't use bitmaps at all -
for performance reasons.
Dont take the responsibility for speaking for anyone but yourself.
I believe my statement was asserted as an opinion, not as fact, so I
completly own that opinion. Telling me I should not have such an
opinion without supporting argument is not going to change my position.
To defend your post, you reference Karl and "most of the people" in this NG.
Is this the case? Have you been authorized to speak in their behalf?
It does not work like this. In a sense, this NG is a "comminity" of
people who choose to work by the rules. I don't like some of the rules
myself but my dislike of them is inconsequential so I (for the most
part) play by the rules. If you want to participate (i.e. get help or
give help), you'll get much better success if you play by the rules.
The rules are clearly stated in the FAQ (which I posted earlier) and so
far I believe that's where you need to go an seek your "authorization".

So now is the time for you to put up some code.

If I wanted to, I would have done that already. I've already given the
best advice I can with my available time. If you take this question to
comp.programming or a better suited NG I honestly think you'll find
better answers.

You seem to have enough time to complain, why not use your time more
constructively?


I don't believe I have made any complaint whatsoever. If you interpret
anything I said as a complaint you are mistaken. Absolutely everything
I have attempted to say to you have been with good intentions.

This medium (the written word) is a poor conveyor of intent and emotion,
hence I am very careful about jumping to conclusions. It's almost
impossible to write anything that can't be misinterpreted.


BTW - I'm probably the worst offender of "answering off-topic questions"
in c.l.c++ (look at the next post -Subj: C vs C++ in pthreads- for
evidence). So when I say it's off topic, I'm usually right by a wide
margin...

If you are the worst offender, why was my post such an offense?


I NEVER intended to offend you. I'll apologise right now - no offence
was intended - even after you called *me* an idiot - I really have no
wish to offend you whatsoever.
What's the point?
To attempt to help you or others wishing to read this.

I've heard people complain about posting to threads off topic, not to groups.
This NG has a very long history of OT fights - some people have become
all bend out of shape because of it. c.l.c++ is unfortunately named in
that some people think that anything that could be remotely related to
C++ get's sent to c.l.c++. If you don't believe this, look at some of
the other posts.

On rare occasion someone will complain about spam porn hitting the NG. It's a matter of opinion as to whether the question was off topic
or not.
In some cases, I agree - in fact, see my response to the thread "C vs.
C++ in pthreads..." which was started just after this one. But this
thread has no hope of being on topic because there is nothing specific
to C++ as written in the standard. Your question has alot more to it
than I think you understand there is. There is a significant investment
in effort to get to a good answer I don't think you'll get the best
answer here.
The NG is as much my resource as anyone else's. If you are bothered by off topic posts, then simply ignore them, your help wasn't help
at all, it was an insult.
The "insult" is all in your mind. Nobody wanted to insult you. I don't
believe anyone else but you would see it that way.

My post could be very much on-topic depending on how you approach it.
Nice try - no cigar :-)

I have several solutions to this problem, I'm looking for suggestions and/or
implementation details, not schooling on how or where to post my question.
If you cant answer it, simply ignore it.


This applies to you too. If you can't stand the advice, ignore it.


Jul 22 '05 #10
On 23 Jan 2004 12:34:18 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
Look up the FAQ, it states it more clearly.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
I know what the FAQ says, having quoted and cited it many times.
Some might say too many times.

"Only post to comp.lang.c++ if your question is about the C++
language itself. For example, C++ code design, syntax, style,
rules, bugs, etc."

The question was about C++ code design, the first of those categories
that Cline mentions.

The question was never off topic. The problem is in your imagination.
You forgot to imagine that the poster had included the magic words "How
should I do this in standard C++?". But those words ought to be assumed
wherever they fit in questions in comp.lang.c++.
So now is the time for you to put up some code.


If I wanted to, I would have done that already. I've already given the
best advice I can with my available time. If you take this question to
comp.programming or a better suited NG I honestly think you'll find
better answers.


You flamed a questioner, and you were wrong, and you were adamantly and
bizarrely wrong. So now you owe it to him to give him some help, by way
of apology. If you do not have time to help, then you do not have time
to post here. It is a bad thing for comp.lang.c++ to have the
reputation as a place to go to get flamed and not get help. If a
question can plausibly be interpreted as on topic, then interpret it
that way. If part of the question is on topic, then answer that part.

You will find that the C++ code to do this is not so easy, probably why
he came here with his question anyway. Maybe you are incapable of
writing it.
BTW - I'm probably the worst offender of "answering off-topic questions"


So, don't do that, it's also part of the problem. "How should I do this
in standard C++" is not off-topic - it IS the topic.

Jul 22 '05 #11
David Harmon wrote:
On 23 Jan 2004 12:34:18 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
Look up the FAQ, it states it more clearly.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

I know what the FAQ says, having quoted and cited it many times.
Some might say too many times.

"Only post to comp.lang.c++ if your question is about the C++
language itself. For example, C++ code design, syntax, style,
rules, bugs, etc."

The question was about C++ code design, the first of those categories
that Cline mentions.

The question was never off topic. The problem is in your imagination.
You forgot to imagine that the poster had included the magic words "How
should I do this in standard C++?". But those words ought to be assumed
wherever they fit in questions in comp.lang.c++.


I think you're wrong.

Take this question : "I'd like to design a program in C++ that solves
world hunger - can someone help me write such a program please ?"

Such a question is "off topic" - replace the "world hunger" the bit run
requirement and it's still off topic.

So now is the time for you to put up some code.
If I wanted to, I would have done that already. I've already given the
best advice I can with my available time. If you take this question to
comp.programming or a better suited NG I honestly think you'll find
better answers.

You flamed a questioner, and you were wrong, and you were adamantly and
bizarrely wrong. So now you owe it to him to give him some help, by way
of apology.


Please cite the words you believe "flamed a questioner". Once you have
found such words, try to say them exactly without any thoughts of
flaming in your head and you'll find that you mis-interpretted them.

As I have already written, I take caution in interpretting emotional
responses becuase it's too easy make errors. Writing responses that
can't be interpreted emotionally is night impossible to do. Hence the
flame is usually in the eye of the beholder.
If you do not have time to help, then you do not have time to post here.
(Arrogance alert.) I'd like to see you justify this comment.

It is a bad thing for comp.lang.c++ to have the reputation as a place to go to get flamed and not get help.
Not everyone can be helped. If someone is too arrogant to see the help
when they get it, that's not my problem. One day they may grow out of
it, some never do. I'll not loose any sleep over that.

If a question can plausibly be interpreted as on topic, then interpret it
that way. If part of the question is on topic, then answer that part.
Go ahead - nobody is stopping you.

You will find that the C++ code to do this is not so easy, probably why
he came here with his question anyway. Maybe you are incapable of
writing it.
Well, there is nothing C++ about it then is there ? It's simply a hard
problem regarless of language. Actually, it's probably harder that the
OP thought it was because if performance is an issue, you may want to
cache a free list/tree.

BTW - I'm probably the worst offender of "answering off-topic questions"

So, don't do that, it's also part of the problem. "How should I do this
in standard C++" is not off-topic - it IS the topic.


Great, I have a question for you "Can you please show me a program that
that computes free body trajectories at the quantum level using standard
C++ ?"

Jul 22 '05 #12
On 23 Jan 2004 21:10:25 EST in comp.lang.c++, Gianni Mariani
<gi*******@mariani.ws> was alleged to have written:
Please cite the words you believe "flamed a questioner".


You are right. I was wrong. I apologize for the accusation.
I seem to have conflated David Mott's response to you with what you
actually wrote. Which does pretty well wipe out most of what I said,
except that I still think the original question should be interpreted
as being about C++ programming, and thereby on topic.
Sorry.
Jul 22 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
0
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and...
4
by: Peter Rilling | last post by:
Does VS.NET 2005 Professional support integrated unit testing, or is that only with the team system?
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
58
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes)....
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.