I'm donating my vector lib.

This is a discussion on I'm donating my vector lib. within the C Programming forums, part of the General Programming Boards category; Too late now. Anyway, what fixes would be worth making someone share their update? I'm only continuing now for the ...

  1. #16
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Too late now. Anyway, what fixes would be worth making someone share their update? I'm only continuing now for the fun of it. Did you know code posted here is implied to be copyrighted(under US/international law)? You literally have to specify it as under * license or the user is in violation of your rights. It's a weird law, isn't it?

    Note how I give the user a chance to free their data before I destroy the node.
    Yours is different there, you set your "void* data" directly to the users data, I allocate new space with malloc and copy their data there, and set my "void* data" to the copied version. Mine has an extra layer of abstraction(not that I'm saying it's better, my abstraction has to take away quite a bit from speed).

  2. #17
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Probably it'd be good if
    struct vector *copy_vector_range(struct vector *v,int from,int to);
    Then you've slices!
    If the size of element is small (like int or even double) compared to pointer node. You might just want to use array and use linked list for large object like struct.

  3. #18
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    > struct vector *copy_vector_range(struct vector *v,int from,int to);
    I can do that. I probably won't do it tonight, but I'll get it done. I noticed you've picked up my naming scheme, don't get used to it. I liked that other guy's(the other dude that posted code idk his nick) and have been changing some stuff. I'm not going to post it all again, I'll edit my original post when I'm done for the night.

    > If the size of element is small (like int or even double) compared to pointer node. You might just want to use array and use linked list for large object like struct.
    No way! I did all this work to have a data structure that is accessible by indexes, that grows automatically. Why would I want to use an array, then I lose the auto-allocate on write? Memory's cheep anyway, I've got 3g(2.7 for system use) and Linux barely ever gets above 1!

  4. #19
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Take a look at glib. It has linked list, hash table,tree, queue,stack, scanner,string, array ,etc...

    And how about being able to insert at any position.
    i.e insert( list, 1000 , /*at 1000 position */
    data);

    Code:
          
          size_t list_count( ) returns number of items in list.
          // searching
          void * search( v, int (*compare)(const void*,const void*), to_search);
          // sorting
          void sort( v, int (*compare)(const void *,const void*) );
         // reverse
          void reverse(v)
    Last edited by Bayint Naung; 06-24-2010 at 01:25 AM.

  5. #20
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    I need to find a project to work on. Does anyone here have a pretty big project they'd be willing to take on help with? I'm better at system-level programming than this type of stuff, but I enjoy it all.

  6. #21
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by User Name: View Post
    I need to find a project to work on. Does anyone here have a pretty big project they'd be willing to take on help with? I'm better at system-level programming than this type of stuff, but I enjoy it all.
    Take a look at SourceForge.net: Help Wanted or start your own...

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Quote Originally Posted by User Name: View Post
    I love the idea of a for_each type function, but I'm not sure if I can figure out how to implement it. I'll try. I'm having a problem with making everything const, I get all kinds of errors for trying to modify the vector structures. How do I cast away const-ness?
    If you need get const errors, then you aren't using const properly. You are NOT supposed to modify data that is const.
    If you need to do that, then it shouldn't be const.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    It needs to be const to keep the user from modifying, but my lib has to modify it. How else do I keep the user from modifying it?

    it = the vector structure

  9. #24
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Just don't let the user know of the structure.

    in vector.h :
    Code:
    typedef struct vector_s vector;
    in vector.c:
    Code:
    #include "vector.h"
    
    struct vector_s {
       void * data;
       int x;
    };
    You need not expose the implementation of "vector". As for the const, I was talking about return values and parameters to functions. Your "get last error" return pointer should be const for example.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21