[x265] [PATCH] List: std::list Implementation

Steve Borho steve at borho.org
Mon Sep 16 21:10:51 CEST 2013


On Mon, Sep 16, 2013 at 5:31 AM, Gopu Govindaswamy <
gopu at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Gopu Govindaswamy <gopu at multicorewareinc.com>
> # Date 1379327475 -19800
> # Node ID e499466c7c6591345af2a625da12185c7735347b
> # Parent  6bab41a554b36133865fe3378964cb9e76c24ebd
> List: std::list Implementation
>
> To remove the std::list dependency from X265,  and this class can be
> enhanced based on the types of std::list API's used in current x265
>
> diff -r 6bab41a554b3 -r e499466c7c65 source/common/CMakeLists.txt
> --- a/source/common/CMakeLists.txt      Fri Sep 13 17:24:05 2013 +0530
> +++ b/source/common/CMakeLists.txt      Mon Sep 16 16:01:15 2013 +0530
> @@ -16,8 +16,10 @@
>
>  file(GLOB LIBCOMMON_HDR ../Lib/TLibCommon/*.h)
>  file(GLOB LIBCOMMON_SRC ../Lib/TLibCommon/*.cpp)
>

the CMakeLists.txt file in the source/ folder will need a line like this:

include_directories(util)


> +file(GLOB LIBUTIL ../util/*.cpp ../util/*.h)
>

the LIB prefix to LIBUTIL is unnecessary, it doesn't live in the Lib/ folder


>  source_group(TLibCommon FILES ${LIBCOMMON_SRC})
>  source_group(TLibCommonH FILES ${LIBCOMMON_HDR})
> +source_group(Util FILES ${LIBUTIL})
>  if(GCC)
>      set_source_files_properties(${LIBCOMMON_SRC} PROPERTIES COMPILE_FLAGS
>          "-Wno-sign-compare")
> @@ -38,7 +40,7 @@
>  endif(MSVC)
>
>  add_library(common STATIC ../../COPYING
> -    ${LIBCOMMON_SRC} ${LIBCOMMON_HDR}
> +    ${LIBCOMMON_SRC} ${LIBCOMMON_HDR} ${LIBUTIL}
>      primitives.cpp primitives.h
>      pixel.cpp dct.cpp ipfilter.cpp intrapred.cpp
>      ../VectorClass/instrset_detect.cpp
> diff -r 6bab41a554b3 -r e499466c7c65 source/util/list.h
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/source/util/list.h        Mon Sep 16 16:01:15 2013 +0530
> @@ -0,0 +1,158 @@
>
> +/*****************************************************************************
> + * Copyright (C) 2013 x265 project
> + *
> + * Authors: Gopu Govindaswamy <gopu at multicorewareinc.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111,
> USA.
> + *
> + * This program is also available under a commercial proprietary license.
> + * For more information, contact us at licensing at multicorewareinc.com.
> +
> *****************************************************************************/
> +
> +#ifndef X265_LIST_H
> +#define X265_LIST_H
> +
> +#include "common.h"
> +
> +// Short Notes:
> +// Under development
> +// this class is used to remove the std::list dependency from x265,
> +// Providing Minimum std::list API implementation
>

either list a negative list (of unsupported APIs) or a positive list (of
supported APIs).  I'm not sure I follow the capitalization policy of that
sentence.


> +// this class can be enhanced based on types of std::list API's used in
> current x265
>

this comment is pretty redundant, can be removed.  You could say we only
support APIs used by x265, which is at least informative.

Also add a comment stating this class does not pretend to be thread-safe


> +
> +template<class T>
> +struct List
> +{
> +private:
> +
> +    struct Node
> +    {
> +        T object;
> +        Node* next;
> +    };
> +
> +public:
> +
> +    Node* head;
> +    Node* tail;
> +    int size;
> +
> +    List() { head = 0; size = 0; }
>

tail is uninitialized


> +
> +    inline T* begin() { return head; }
> +
> +    inline T* end() { return tail; }
> +
> +    inline bool isEmpty()
> +    {
>

would be helpful to assert head == NULL and size == 0 here


> +        if (head == NULL)
> +            return true;
> +        else
> +            return false;
> +    }
> +
> +    inline void push_back(T value)
> +    {
> +        if (head == NULL)
> +        {
> +            head = (Node*)X265_MALLOC(Node, sizeof(Node));
>

these mallocs are wrong.  the arguments to X265_MALLOC are type, count


> +            head->object = value;
> +            head->next = NULL;
> +            tail = head;
> +        }
> +        else
> +        {
> +            Node *nodePtr = tail;
> +            nodePtr->next = (Node*)X265_MALLOC(Node, sizeof(Node));
> +            nodePtr->next->object = value;
> +            nodePtr->next->next = NULL;
> +            tail = nodePtr->next;
> +        }
> +        size += 1;
> +    }
> +
> +    inline void push_front(T value)
> +    {
> +        if (head == NULL)
> +        {
> +            head = (Node*)X265_MALLOC(Node, sizeof(Node));
> +            head->object = value;
> +            head->next = NULL;
> +            tail = head;
> +        }
> +        else
> +        {
> +            Node *front;
> +            front = (Node*)X265_MALLOC(Node, sizeof(Node));
> +            front->object = value;
> +            front->next = head;
> +            head = front;
> +        }
> +        size += 1;
> +    }
> +
> +    inline void pop_front()
> +    {
> +        if (head != NULL)
> +        {
> +            if (head->next == NULL)
> +                X265_FREE(head);
> +            else
> +            {
> +                Node *temp = head->next;
> +                X265_FREE(head);
> +                head = temp;
> +            }
> +            size -= 1;
> +        }
> +    }
> +
> +    inline void pop_back()
> +    {
> +        if (head != NULL)
> +        {
> +            if (head->next == NULL)
> +                X265_FREE(head);
>

uhm, no. this is all-bad


> +            else
> +            {
> +                Node *ptr = head, *ptr1 = NULL;
> +                while (ptr->next != NULL)
> +                {
> +                    ptr1 = ptr;
> +                    ptr = ptr->next;
> +                }
> +
> +                X265_FREE(ptr1->next);
> +                ptr1->next = NULL;
> +            }
> +            size -= 1;
> +        }
>

to do this efficiently it needs to be doubly-linked


> +    }
> +
> +    inline void remove_all()
> +    {
> +        Node *temp = head;
> +        Node *remove;
> +
> +        while (temp->next != NULL)
> +        {
> +            remove = temp->next;
> +            X265_FREE(temp);
> +            temp = remove;
> +        }
> +    }
> +};
> +
> +#endif // ifndef X265_LIST_H
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>



-- 
Steve Borho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20130916/a4abb21c/attachment.html>


More information about the x265-devel mailing list