Data structure problem.....

A

adil.mohd

Hi All,

This is my first to this group. I have a linklist implementation. I
want to put some checks in the implementation code
so that i can detect any problem with the list and capture some data
to prove the problem.

Any suggestion or code fragments are welcome .

Thanks,
Adil
 
V

Victor Bazarov

This is my first to this group.

Have you read the FAQ yet?
I have a linklist implementation.

I guess you're asking us to take your word for it. OK.
I
want to put some checks in the implementation code
so that i can detect any problem with the list and capture some data
to prove the problem.

What would you consider a "problem with the list"?
Any suggestion or code fragments are welcome .

Yes. Please post some code fragments so we could actually make some
suggestions.

V
 
A

adil.mohd

Have you read the FAQ yet?


I guess you're asking us to take your word for it. OK.


What would you consider a "problem with the list"?


Yes. Please post some code fragments so we could actually make some
suggestions.

V


Basically, I want to inroduce some sanity checks in
implementation....
I would like to know if I can do that. Also if it is a standard
practice.

Example of these consistency or sanity checks would be
, after adding or deleting a node If I can somehow find that the list
has been corrupted or not.
In case the list got corrupted I would like to capture some
information
regarding the nodes involved in the list corruption.
By corruption I mean if the list got broken or anything bad.

The implementation is based on a fast fail strategy. I would like to
fail in the
implementation as soon as some sanity check failed rather than
continue and corrupt
other data structures if anything goes bad with the list.
 
A

Alf P. Steinbach

* (e-mail address removed):
Basically, I want to inroduce some sanity checks in
implementation....
I would like to know if I can do that. Also if it is a standard
practice.

Example of these consistency or sanity checks would be
, after adding or deleting a node If I can somehow find that the list
has been corrupted or not.
In case the list got corrupted I would like to capture some
information
regarding the nodes involved in the list corruption.
By corruption I mean if the list got broken or anything bad.

The implementation is based on a fast fail strategy. I would like to
fail in the
implementation as soon as some sanity check failed rather than
continue and corrupt
other data structures if anything goes bad with the list.

This sounds like an academic problem.

You can always use e.g. "assert" to introduce precondition and
postcondition checks. For a linked list these checks will in general be
more complicated and far less efficient (say, linear time) than the code
itself, hence of very dubious value. Mostly, they'll have negative value.

Instead of doing such a thing, use std::list.
 
C

Colander

Hi All,

This is my first to this group. I have a linklist implementation. I
want to put some checks in the implementation code
so that i can detect any problem with the list and capture some data
to prove the problem.

Any suggestion or code fragments are welcome .

As others have mentioned it's difficult to give examples without
anything from you to go on, but a try:

LinkedList::clear()
{
// some of your code that clears the list
....
// the end of your code

// Then add something like this:
assert(size() == 0);
}
 
A

adil.mohd

* (e-mail address removed):










This sounds like an academic problem.

You can always use e.g. "assert" to introduce precondition and
postcondition checks. For a linked list these checks will in general be
more complicated and far less efficient (say, linear time) than the code
itself, hence of very dubious value. Mostly, they'll have negative value.

Instead of doing such a thing, use std::list.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted text -

- Show quoted text -

Yes I need inputs at acaedemic level only. I would love to use
standard linklist implementation but
my requirement is slightly different.

I dont do dynamic memory allocations. I have memory mapped file which
is a chunk of
memory multiple of a particular memory structure. Now the data
structure I am using
contains indexes of other data structures in the file. The index into
the file is basically a link
to the next data structure. So I implemented a cutomized list
implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,290
Messages
2,571,453
Members
48,129
Latest member
DianneCarn

Latest Threads

Top