simple data structure @ coscup 2013

12

Click here to load reader

Upload: chien-hung-pan

Post on 23-Jun-2015

937 views

Category:

Technology


1 download

DESCRIPTION

https://github.com/starnight/simple-data-structure Video @ COSCUP 2013 http://www.youtube.com/watch?v=rv9GH4pDcvQ&feature=share&list=PLe8-eLy4w2ytwzkFPrbTt2Udq7vmQtiRV

TRANSCRIPT

Page 1: Simple Data Structure @ COSCUP 2013

Simple Data StructureA simple data structure framework

implemented in CStarNight @ COSCUP 2013

Page 2: Simple Data Structure @ COSCUP 2013

Who am I?

潘建宏 (StarNight)mail : [email protected]

出沒在~PTT : zack2004plurk : StarNightFacebook : Jian-Hong PanGitHub : starnight

現在研替剛結束,暫時繼續在種花店當個打雜園丁 ~

Page 3: Simple Data Structure @ COSCUP 2013

Outline

1. What is it?

2. Why do this?

3. How to use it?a. Structure Typesb. Dedicated Functionsc. Public Functions

4. Demo

Page 4: Simple Data Structure @ COSCUP 2013

What is Simple Data Structure?

● You can have it from the GitHub (include Wiki):

https://github.com/starnight/simple-data-structure

● A "simple" data structure framework implemented in C

● Implemented QUEUE, STACK and RING (Circular Buffer)

1.0.0 Release now!!!

Page 5: Simple Data Structure @ COSCUP 2013

Why do Simple Data Structure?

1. We have to use the queue, stack ... data

structures in embedded system with limited

resources.

2. There are native defined templates, classes,

interface or functions in C++, .NET, Perl,

PHP, Python and Java ... .

3. But, C does not.

Page 6: Simple Data Structure @ COSCUP 2013

沒有喜歡的,就自幹一個!!!

by  慣C  大神s

So, code it by myself in C

Page 7: Simple Data Structure @ COSCUP 2013

Structure Typesstruct _SDS_BUFFER { uint8_t type; /* The data structure type. */ uint8_t len; /* The buffer array length. */ uint8_t inpos; /* The next input position. */ uint8_t outpos; /* The next output position. */ void *elems; /* The pointer of buffer array. */};

SDS_QUEUE, SDS_STACK and SDS_RING is _SDS_BUFFER.

Page 8: Simple Data Structure @ COSCUP 2013

_SDS_BUFFERtype

len

inpos

outpos

*elems

Buffer Arrayin Memory

element #0

element #1

element #2

element #3

element #4

.

.

.

element #len-1

Could be any data type array

Page 9: Simple Data Structure @ COSCUP 2013

Dedicated Functions

● SDSInitQueue, SDSInitStack, SDSInitRing

● SDSPushQueue, SDSPushStack, SDSPushRing

● SDSPopQueue, SDSPopStack, SDSPopRing

● SDSFrontQueue, SDSTopStack, SDSFrontRing

● SDSBackQueue, SDSBackStack, SDSBackRing

Page 10: Simple Data Structure @ COSCUP 2013

Public Functions

● SDSEmpty: Data structure is empty or not.

● SDSSize: Number of elements in the buffer.

● SDSPush: Push an element into the buffer.

● SDSPop: Pop the first ordered element from

the buffer.

● SDSFront: Access next element.

● SDSBack: Access last element.

Page 11: Simple Data Structure @ COSCUP 2013

Demo1. Have a SDS_QUEUE data structure.

2. Define the length of the buffer.

3. Have an integer buffer array.

4. Initial the queue with assigned length and the buffer array.

5. Use it with SDSPush/Pop/Front/Back functions.

Demo codes:https://github.com/starnight/simple-data-structure/#quick-start

Page 12: Simple Data Structure @ COSCUP 2013

End & Thanks ~