www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - LinkedList and Deque API in DCollections

reply d coder <dlang.coder gmail.com> writes:
--f46d04083de73dc5ab04c2fb032c
Content-Type: text/plain; charset=ISO-8859-1

Greetings

I do not know if this email belongs to this list or not. It is about a
package available at dsource. Let me know if I should be posting such
emails elsewhere.

I need an implementation of Doubly Linked list and Deque. Since the
std.container library does not support these containers yet, I am trying to
use these from DCollections library available on DSource here
http://www.dsource.org/projects/dcollections . I am using the D2 branch of
this library.

Now the issue is, I could not find any API for adding elements to the
beginning of the LinkList. In the documentation (which is there for D1
version) I see methods like append and prepend, but I do not think these
are implemented in the D2 version of the library. And I see that for Deque,
only prepend is implemented, there is no append.

Also it is not clear to me if the "add" method could be used to append
elements on the back of the LinkList or Deque collection.

Thanks and Regards
- Puneet

--f46d04083de73dc5ab04c2fb032c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Greetings<div><br></div><div>I do not know if this email belongs to this li=
st or not. It is about a package available at dsource. Let me know if I sho=
uld be posting such emails elsewhere.</div><div><br></div><div>I need an im=
plementation of Doubly Linked list and Deque. Since the std.container libra=
ry does not support these containers yet, I am trying to use these from DCo=
llections library available on DSource here=A0<a href=3D"http://www.dsource=
.org/projects/dcollections" target=3D"_blank">http://www.dsource.org/projec=
ts/dcollections</a> . I am using the D2 branch of this library.</div>


<div><br></div><div>Now the issue is, I could not find any API for adding e=
lements to the beginning of the LinkList. In the documentation (which is th=
ere for D1 version) I see methods like append and prepend, but I do not thi=
nk these are implemented in the D2 version of the library. And I see that f=
or Deque, only prepend is implemented, there is no append.</div>


<div><br></div><div>Also it is not clear to me if the &quot;add&quot; metho=
d could be used to append elements on the back of the LinkList or Deque col=
lection.</div><div><br></div><div>Thanks and Regards</div><div>- Puneet</di=
v>


<div><br></div>

--f46d04083de73dc5ab04c2fb032c--
Jun 21 2012
next sibling parent reply travert phare.normalesup.org (Christophe Travert) writes:
d coder , dans le message (digitalmars.D:170392), a écrit :
 --f46d04083de73dc5ab04c2fb032c
 Content-Type: text/plain; charset=ISO-8859-1
 
 Greetings
 
 I do not know if this email belongs to this list or not. It is about a
 package available at dsource. Let me know if I should be posting such
 emails elsewhere.
 
 I need an implementation of Doubly Linked list and Deque. Since the
 std.container library does not support these containers yet, I am trying to
 use these from DCollections library available on DSource here
 http://www.dsource.org/projects/dcollections . I am using the D2 branch of
 this library.
 
 Now the issue is, I could not find any API for adding elements to the
 beginning of the LinkList. In the documentation (which is there for D1
 version) I see methods like append and prepend, but I do not think these
 are implemented in the D2 version of the library. And I see that for Deque,
 only prepend is implemented, there is no append.

 Also it is not clear to me if the "add" method could be used to append
 elements on the back of the LinkList or Deque collection.

Did you try : list.insert(list.begin, value);
Jun 21 2012
parent travert phare.normalesup.org (Christophe Travert) writes:
d coder , dans le message (digitalmars.D:170396), a écrit :
 --e0cb4efe2a2821373604c2fc4a15
 Content-Type: text/plain; charset=ISO-8859-1
 
 Did you try : list.insert(list.begin, value);

Thanks. But I believe append and prepend are too common use-cases to be ignored. Also, I see that "assert(some-expression)" has been used at a lot of places in the code of the libraries. Since these libraries are built with -release option, should these assert statements not be replaced by "enforce"?

auto append(T, V)(ref T t, V value) { return t.insert(t.begin, value); } should do the trick. (you may add a guard to make sure T is a container)
Jun 21 2012
prev sibling next sibling parent d coder <dlang.coder gmail.com> writes:
--e0cb4efe2a2821373604c2fc4a15
Content-Type: text/plain; charset=ISO-8859-1

 Did you try : list.insert(list.begin, value);

Thanks. But I believe append and prepend are too common use-cases to be ignored. Also, I see that "assert(some-expression)" has been used at a lot of places in the code of the libraries. Since these libraries are built with -release option, should these assert statements not be replaced by "enforce"? Regards - Puneet --e0cb4efe2a2821373604c2fc4a15 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi= n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class= =3D"h5"><br> </div></div>Did you try : list.insert(list.begin, value);<br> </blockquote></div><br><div>Thanks. But I believe append and prepend are to= o common use-cases to be ignored.</div><div><br></div><div>Also, I see that= &quot;assert(some-expression)&quot; has been used at a lot of places in th= e code of the libraries. Since these libraries are built with -release opti= on, should these assert statements not be replaced by &quot;enforce&quot;?<= /div> <div><br></div><div>Regards</div><div>- Puneet</div> --e0cb4efe2a2821373604c2fc4a15--
Jun 21 2012
prev sibling next sibling parent d coder <dlang.coder gmail.com> writes:
--f46d04016c2900154104c2fca91d
Content-Type: text/plain; charset=ISO-8859-1

 Also, I see that "assert(some-expression)" has been used at a lot of
 places in the code of the libraries. Since these libraries are built with
 -release option, should these assert statements not be replaced by
 "enforce"?

Ok I think asserts are fine since these would be taken out and the library becomes more efficient without these checks. Please ignore. Regards - Puneet --f46d04016c2900154104c2fca91d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote"><br><blockquote class=3D"gmail_quote" style=3D"m= argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also, I see t= hat &quot;assert(some-expression)&quot; has been used at a lot of places in= the code of the libraries. Since these libraries are built with -release o= ption, should these assert statements not be replaced by &quot;enforce&quot= ;?</blockquote> </div><br><div>Ok I think asserts are fine since these would be taken out a= nd the library becomes more efficient without these checks. Please ignore.<= /div><div><br></div><div><br></div><div>Regards</div><div>- Puneet</div> --f46d04016c2900154104c2fca91d--
Jun 21 2012
prev sibling next sibling parent d coder <dlang.coder gmail.com> writes:
--f46d0401fde1774a5c04c2fd1846
Content-Type: text/plain; charset=ISO-8859-1

 auto append(T, V)(ref T t, V value)
 {
  return t.insert(t.begin, value);
 }

 should do the trick.
 (you may add a guard to make sure T is a container)

Thanks Christophe. I think you are relying on UFCS here. So cool. Regards - Puneet --f46d0401fde1774a5c04c2fd1846 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi= n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"=
<br>

{<br> =A0return t.insert(t.begin, value);<br> }<br> <br> should do the trick.<br> (you may add a guard to make sure T is a container)<br> </blockquote></div><br><div>Thanks Christophe. I think you are relying on U= FCS here.</div><div>So cool.</div><div><br></div><div>Regards</div><div>- P= uneet</div><div><br></div> --f46d0401fde1774a5c04c2fd1846--
Jun 21 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 21 Jun 2012 08:53:33 -0400, d coder <dlang.coder gmail.com> wrote:

 Greetings

 I do not know if this email belongs to this list or not. It is about a
 package available at dsource. Let me know if I should be posting such
 emails elsewhere.

This list is fine, you can also create tickets for the TRAC instance for dcollections. http://www.dsource.org/projects/dcollections/newticket
 I need an implementation of Doubly Linked list and Deque. Since the
 std.container library does not support these containers yet, I am trying  
 to
 use these from DCollections library available on DSource here
 http://www.dsource.org/projects/dcollections . I am using the D2 branch  
 of
 this library.

 Now the issue is, I could not find any API for adding elements to the
 beginning of the LinkList. In the documentation (which is there for D1
 version) I see methods like append and prepend, but I do not think these
 are implemented in the D2 version of the library. And I see that for  
 Deque,
 only prepend is implemented, there is no append.

prepend should be implemented for LinkedList, that is an oversight. Yes, you can use insert(ll.begin, elem), but the API should be consistent across containers.
 Also it is not clear to me if the "add" method could be used to append
 elements on the back of the LinkList or Deque collection.

Append is actually implemented via add. For lists, add always adds to the end (including ArrayList, LinkList and Deque). This is not a requirement of the interface, but it happens to be how it's implemented for all the current containers. This should be noted in the docs (which I profusely apologize for not having available). I should make an alias to append from add. -Steve
Jun 25 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 21 Jun 2012 10:24:57 -0400, d coder <dlang.coder gmail.com> wrote:

 Did you try : list.insert(list.begin, value);

Thanks. But I believe append and prepend are too common use-cases to be ignored. Also, I see that "assert(some-expression)" has been used at a lot of places in the code of the libraries. Since these libraries are built with -release option, should these assert statements not be replaced by "enforce"?

No, if you want to use those asserts, build dcollections with debug flag. It's quite impossible for me to tell whether you want the asserts or not. There isn't currently an easy way to build without -release with my build scripts, I should add that. Also note that in most cases, you will not have to do this -- all dcollections objects are templates, which means they get instantiated in non-release mode if that's how you compile your code that uses it. -Steve
Jun 25 2012
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 25 Jun 2012 09:44:12 -0400, Steven Schveighoffer  
<schveiguy yahoo.com> wrote:

 No, if you want to use those asserts, build dcollections with debug flag.

Should have said "without release flag", you don't need to build with debug flag. -Steve
Jun 25 2012