[x265] [PATCH] List: Basic List Operations To Replace std::list
Gopu Govindaswamy
gopu at multicorewareinc.com
Thu Sep 12 09:54:34 CEST 2013
# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1378972464 -19800
# Node ID 7be0ceae34e059849737050c52a326becd8bbf1a
# Parent 0482a5c72c21dc14d6be5f4b9c4ffe2ae574ebc3
List: Basic List Operations To Replace std::list
diff -r 0482a5c72c21 -r 7be0ceae34e0 source/common/list.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/common/list.h Thu Sep 12 13:24:24 2013 +0530
@@ -0,0 +1,154 @@
+/*****************************************************************************
+ * 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 __LIST__
+#define __LIST__
+
+#include "common.h"
+
+template<class T>
+class List
+{
+private:
+
+ struct Node
+ {
+ T value;
+ Node* next;
+ Node(T temp, Node * n = NULL)
+ {
+ value = temp;
+ next = n;
+ }
+ };
+
+public:
+
+ Node* head;
+ int size;
+
+ List() { head = 0; size = 0; }
+
+ inline T* begin() { return head }
+
+ inline bool isEmpty()
+ {
+ if (head == NULL)
+ return true;
+ else
+ return false;
+ }
+
+ inline T* end()
+ {
+ while (head->next != NULL)
+ {
+ head = head->next;
+ }
+ return head;
+ }
+
+ inline void push_back(T value)
+ {
+ if (head == NULL)
+ head = new Node(value);
+ else
+ {
+ Node * nodePtr = head;
+ while (nodePtr->next != NULL)
+ {
+ nodePtr = nodePtr->next;
+ }
+
+ nodePtr->next = new Node(value);
+ }
+ size += 1;
+ }
+
+ inline void push_front(T value)
+ {
+ if (head == NULL)
+ head = new Node(value);
+ else
+ {
+ Node *nodeptr;
+ nodeptr = new Node(value);
+ nodeptr->next = head;
+ head = nodeptr;
+ }
+ size += 1;
+ }
+
+ inline void pop_front()
+ {
+ if (head != NULL)
+ {
+ if (head->next == NULL)
+ delete head;
+ else
+ {
+ Node *temp = head->next;
+ delete head;
+ head = temp;
+ }
+ size -= 1;
+ }
+ }
+
+ inline void pop_back()
+ {
+ if (head != NULL)
+ {
+ if (head->next == NULL)
+ delete head;
+ else
+ {
+ Node *ptr = head, *ptr1;
+ while (ptr->next != NULL)
+ {
+ ptr1 = ptr;
+ ptr = ptr->next;
+ }
+
+ delete ptr1->next;
+ ptr1->next = NULL;
+ }
+ size -= 1;
+ }
+ }
+
+ inline void remove_all()
+ {
+ Node *temp = head;
+ Node *rm;
+
+ while (temp->next != NULL)
+ {
+ rm = temp->next;
+ delete temp;
+ temp = rm;
+ }
+ }
+};
+
+#endif // ifndef __COMMON__
More information about the x265-devel
mailing list