What is a chunklist?

A

Aneel

Please tell me what a chunklist is. Is it a list of linkedlists? Or
list of pointers to nodes? Please explain.
Tomorrow is my paper of Computer Programming(in C++). I couldn't get
the concept of chunklist told by teacher very briefly.
Please anyone tell me what a chunklist is. Thanks
 
K

Kai-Uwe Bux

Aneel said:
Please tell me what a chunklist is. Is it a list of linkedlists? Or
list of pointers to nodes? Please explain.
Tomorrow is my paper of Computer Programming(in C++). I couldn't get
the concept of chunklist told by teacher very briefly.
Please anyone tell me what a chunklist is. Thanks

The C++ standard does not use the term "chunklist". It's not a C++ term.

As for possible meanings, GIYF. However, it is not certain that the term was
used in your class in the same way as it appears in search results. Your
best bet would be to ask your fellow students, the TA, or the teacher. But I
am getting into off-topic stuff.


Best

Kai-Uwe Bux
 
R

Rolf Magnus

Aneel said:
Please tell me what a chunklist is.

Not somehting that has a defined meaning in standard C++.
A quick search with google gave me this:
http://cslibrary.stanford.edu/103/LinkedListBasics.pdf

"Instead of storing a single client element in each node, store
a little constant size array of client elements in each node. Tuning the
number of elements per node can provide different performance
characteristics: many elements per node has performance more like an
array, few elements per node has performance more like a linked list. The
Chunk List is a good way to build a linked list with good performance."
 
K

Keith H Duggar

Please tell me what a chunklist is. Is it a list of linkedlists? Or
list of pointers to nodes? Please explain.
Tomorrow is my paper of Computer Programming(in C++). I couldn't get
the concept of chunklist told by teacher very briefly.
Please anyone tell me what a chunklist is. Thanks

http://en.wikipedia.org/wiki/Unrolled_linked_list

Beyond that as your fellow students for help as Kai-Uwe suggested.

KHD
 
D

DeMarcus

Interesting :) I note there's a C++ implementation here:

http://en.literateprograms.org/Unrolled_linked_list_(C_Plus_Plus)

Is there a reason why there isn't an implementation in something like
Boost though? (Such as that it's not too useful in practice?) It looks
like the sort of thing that would be a likely candidate, no?

Are unrolled linked lists widely-used (and I just hadn't realised), or a
bit obscure?

Cheers,
Stu

I'd guess that every structure fits at least some project.
Here's another list structure.

http://en.wikipedia.org/wiki/Skip_list
 
K

Keith H Duggar

Interesting :) I note there's a C++ implementation here:

http://en.literateprograms.org/Unrolled_linked_list_(C_Plus_Plus)

Is there a reason why there isn't an implementation in something like
Boost though? (Such as that it's not too useful in practice?) It looks
like the sort of thing that would be a likely candidate, no?

Yeah, I agree it's the kind of thing one might expect to find in
Boost. I can't personally comment on why it's not there yet; I'm
sure there are many possible reasons but I'm as curious as you.
Are unrolled linked lists widely-used (and I just hadn't
realised), or a bit obscure?

Well they are one method of implementing deques. For example I'm
pretty sure Python does (or did) implement deques this way. STL
implementations tend to use arrays of arrays instead.

My impression (and it's just a weak impression) is that they are
not "widely" used but not quite "obscure" either. Probably closer
a bit to obscure than widely however.

I think I first ran into them when reading about CDR coding used
in some Lisp implementations.

KHD
 
K

Keith H Duggar

I'm half tempted to email the guy who wrote the implementation I found
(who seems to be Derrick Coetzee) to see if he thinks it might be worth
submitting it to Boost actually. I would write my own and propose it,
but it seems silly to duplicate the effort (and in any case, his looks
pretty reasonable and probably better than what I'd come up with). I
guess it's a thought were he not interested though... :)

Good idea. Boost may not have one simply because nobody has yet
submitted one or shown any interest. So if someone, such as you,
took the lead it might well make it in. If I may, I suggest that
you should review/compare Derrick's implementation with Leigh's.
Perhaps there is a superset of good ideas between the two. Also
you might be interested in this blog entry I googled up:

http://experimentgarden.blogspot.com/2009/08/performance-analysis-of-thirty-eight.html
I did think it sounded a bit deque-like actually.


Glad I've come across them in either case :)

Cool! When/if it gets into Boost I'd certainly give it a shot
from time to time.

KHD
 
P

Paul Bibbings

Leigh Johnston said:
That implementation you talk about is not ideal as it is not an STL
compliant container: it does not use an allocator and it default
constructs NODE_SIZE T elements whenever a new node is created which
is not correct from an STL point of view. segmented_array is STL
compliant.

I haven't analysed your segmented_list implementation in any detail, but
I have given it go and run your tests. I notice that there are a couple
of bugs that jump out immediately from the code given at

http://www.i42.co.uk/stuff/segmented_array.h

If you search for the last occurence of `segment_list::iterator' on that
page, this occurence omits a necessary `typename'. (Does this compile
as is using VC - i.e., without the typename?) Also, if you search for
`friend class iterator_base', you will see that you have iterator_base
as a friend of itself.

Regards

Paul Bibbings
 
P

Paul Bibbings

Leigh Johnston said:
Fixed version uploaded to the website. The friend should have been a
template but for some reason this appears to be optional in VC++.

Compiles now without error or warning on gcc-4.4.3 (i686-pc-cygwin,
-Wall).

One other thing I wanted to ask. In both your iterator and
const_iterator classes you provide a private typedef for
iterator_base<...> but you do not use this in the subsequent definitions
of your constructors.

E.g.:

template <
typename T,
std::size_t N = 64,
typename A = std::allocator said:
class segmented_array
{
// ...
public:
class iterator
: public iterator_base<
pointer,
reference,
typename segment_list::iterator,
typename segment::iterator,
segment
{
private:
// ...
typedef iterator_base<
pointer,
reference,
typename segment_list::iterator,
typename segment::iterator,
segment
public:
// ...
iterator(const iterator& x)
: iterator_base< // here
pointer,
reference,
typename segment_list::iterator,
typename segment::iterator,
segment
{ }
// ...
}
// ...
};

There might be a good reason for this that I am not aware of, or perhaps
its conventional? I ask merely because I have seen it many times where
a class scope typedef like this (usually public) is provided but not
used within the definition of the class itself. I was wondering if
there was any reason for avoiding:

iterator(const_iterator& x)
: base(x)
{ }

In your example, you use base elsewhere to good effect. Just wondering.

Regards

Paul Bibbings
 
P

Paul Bibbings

R

red floyd

[redacted]

Is there a reason why there isn't an implementation in something like
Boost though? (Such as that it's not too useful in practice?) It looks
like the sort of thing that would be a likely candidate, no?

Are unrolled linked lists widely-used (and I just hadn't realised), or a
bit obscure?

Isn't that std::deque?
 
P

Paul Bibbings

Leigh Johnston said:
That implementation you talk about is not ideal as it is not an STL
compliant container: it does not use an allocator and it default
constructs NODE_SIZE T elements whenever a new node is created which
is not correct from an STL point of view. segmented_array is STL
compliant.

I have been able to spend a little more time looking through the code
for your segmented_array. I am not a library implementer by any stretch
of the imagination but there does appear to be an amount of interest in
your implementation alongside the idea of whether a chuncklist could be
proposed for inclusion in Boost. I am certainly interested in this as
an idea and, for my own learning, the requirements of STL compliance and
how you attain that in a library container have led me to want to look
more closely at your segmented_array. (I explain this merely to ensure
that any comments that I make will be understood as positively critical
at most and merely questioning at least.)

I was looking, in particular, at the implementation of the comparison
operators for your iterators, and I was noticing what seems to be a
problem or two and was wanting to raise a query also.

If we take your implementation of op== on your iterator_base class, for
example:

template <
typename Pointer2,
typename Reference2,
typename SegmentListIterator2,
typename SegmentIterator2,
typename Segment2
bool operator==(const iterator_base<
Pointer2,
Reference2,
SegmentListIterator2,
SegmentIterator2,
Segment2
>& rhs) const
{ return iPosition == rhs.iPosition; }

it seems that there is an issue here over this definition since it
permits the following:

09:12:32 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $cat src/debug.cpp
#include <cassert>

#include "segmented_array.h"

int main()
{
lib::segmented_array<int> sa_int1;
lib::segmented_array<int> sa_int2;

sa_int1.push_back(1);
sa_int2.push_back(1);

assert(sa_int1.begin() == sa_int2.begin());
}

09:12:48 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $make
Building file: src/debug.cpp
Invoking: gcc as compiler
gcc -O0 -gdwarf-2 -g3 -Wall -Wno-unused -fmessage-length=0
-MMD -MP -o bin/debug.o -c src/debug.cpp
Finished building: src/debug.cpp

Building target: bin/debug
Invoking: g++ as linker
g++ -Wl,--enable-auto-import -static -o bin/debug bin/debug.o
Finished building: bin/debug

09:13:39 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $make run_debug

09:13:46 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $

That is, since it compares only on position, it evaluates as equal two
iterators pointing to the same position in difference containers.
Obviously, if you replaced the use of segmented_array in this test with,
say, std::vector, this test would fail.

Further, I'm trying to understand what the purpose is of having your
operators (as op== here) as function templates parametertized
differently from the type instance itself. I am only beginning
to think this through and so this is just a query, but I notice that in
the specification for std::iterator [lib.iterator.synopsis] the
comparison operators are declared as free functions of the form:

template <class Iterator>
bool operator==(const reverse_iterator<Iterator>& x,
const reverse_iterator<Iterator>& y);

Having experimented with your implementation I have not yet been able to
find a scenario in which I can discover the utility of your
parameterization. As illustrated above, op== returns true for two
iterators of the same type but on different arrays. Yet, if you try to
compare two iterators of different types (i.e., on containers of
different types) then it doesn't even compile.

09:32:11 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $cat src/debug.cpp
// file: debug.cpp

#include <cassert>

#include "segmented_array.h"

int main()
{
lib::segmented_array<int> sa_int1;
lib::segmented_array<double> sa_double1;

sa_int1.push_back(1);
sa_double1.push_back(1);

assert(sa_int1.begin() == sa_double1.begin());
}

09:32:14 Paul Bibbings@JIJOU
/cygdrive/d/CPPProjects/Emacs/segmented_array $make
Building file: src/debug.cpp
Invoking: gcc as compiler
gcc -O0 -gdwarf-2 -g3 -Wall -Wno-unused -fmessage-length=0 -MMD -MP
-o bin/debug.o -c src/debug.cpp
src/debug.cpp: In function ¡®int main()¡¯:
src/debug.cpp:18: error: no match for ¡®operator==¡¯ in
¡®lib::segmented_array<T, N, A>::begin() [with T = int, unsigned
int N = 64u, A = std::allocator<int>]() == lib::segmented_array<T,
N,A>::begin() [with T = double, unsigned int N = 64u, A =
std::allocator<double>]()¡¯
make: *** [bin/debug.o] Error 1

So, I'm not sure what there is in between comparing iterators of the
same type (which compiles, but succeeds too broadly) and comparing
iterators of different types (which fails to compile) that necessitates
the parameterization of your comparison operators as function templates
in this way.

Perhaps you could provide an example that illustrates this
implementation choice. I'm sure I have not yet considered all
possibilities.

Regards

Paul Bibbings
 
P

Paul Bibbings

Leigh Johnston said:
Paul Bibbings said:
Further, I'm trying to understand what the purpose is of having your
operators (as op== here) as function templates parametertized
differently from the type instance itself. I am only beginning
to think this through and so this is just a query, but I notice that in
the specification for std::iterator [lib.iterator.synopsis] the
comparison operators are declared as free functions of the form:

template <class Iterator>
bool operator==(const reverse_iterator<Iterator>& x,
const reverse_iterator<Iterator>& y);

op== is a template so const_iterator can be compared against iterator.

Thanks for clarifying this, Leigh. Had I wanted to make a guess about
the reason I would have thought just that.

Regards

Paul Bibbings
 

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

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top