www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - LinkedList and Deque API in DCollections

reply d coder <dlang.coder gmail.com> writes:
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
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
next sibling parent reply d coder <dlang.coder gmail.com> writes:
 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
Jun 21 2012
next sibling parent reply 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
parent d coder <dlang.coder gmail.com> writes:
 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
Jun 21 2012
prev sibling parent reply "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
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
prev sibling parent d coder <dlang.coder gmail.com> writes:
 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
Jun 21 2012
prev 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