Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.

Commit f37eb8c

Browse files
committed
Initial Import
Add some tests
0 parents  commit f37eb8c

File tree

11 files changed

+789
-0
lines changed

11 files changed

+789
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.beam
2+
*.o
3+
*.plt
4+
*.swp
5+
.DS_Store
6+
.eunit
7+
.rebar
8+
deps
9+
doc/*.css
10+
doc/*.html
11+
doc/edoc-info
12+
doc/erlang.png
13+
ebin
14+
edoc-info
15+
erl_crash.dump
16+
doc/utf8

AUTHORS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright Statements
2+
====================
3+
4+
Copyright (c) 2014 Stéphane Wirtel and the contributors
5+
6+
Contributors
7+
============
8+
9+
Stéphane Wirtel <[email protected]>

LICENSE

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.

NOTICE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
erqueue
2+
-------
3+
4+
2014 (c) Stéphane Wirtel <[email protected]>
5+
6+
erqueue is released under the Mozilla Public License Version 2.0.
7+
See the LICENSE file for the complete license.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
# erqueue - Queue using ETS. #
4+
5+
Copyright (c) 2014 Stéphane Wirtel.
6+
7+
__Version:__ 0.1.0
8+
9+
## Description
10+
11+
The erqueue module implements a queue using the ETS module of Erlang.
12+
13+
## Usage
14+
15+
## Example
16+
17+
## Ownership and License
18+
The contributors are listed in AUTHORS. This project uses the MPL v2 license,
19+
see LICENSE.
20+
21+
erqueue uses the
22+
[C4.1 (Collective Code Construction Contract)](http://rfc.zeromq.org/spec:22)
23+
process for contributions.
24+
25+
## Examples
26+
27+
## Development
28+
29+
Under C4.1 process, you are more than welcome to help us by:
30+
* join the discussion over anything from design to code style
31+
* try out and [submit issue reports](https://github.com/matrixise/erqueue/issues/new) or feature requests
32+
* pick a task in [issues](https://github.com/matrixise/erqueue) ang get it done
33+
* for the repository and have your own fixes
34+
* send us pull requests
35+
36+
37+
## Modules ##
38+
39+
40+
<table width="100%" border="0" summary="list of modules">
41+
<tr><td><a href="http://github.com/matrixise/erqueue/blob/master/doc/erqueue.md" class="module">erqueue</a></td></tr></table>
42+

doc/erqueue.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
2+
3+
# Module erqueue #
4+
* [Data Types](#types)
5+
* [Function Index](#index)
6+
* [Function Details](#functions)
7+
8+
9+
10+
<a name="types"></a>
11+
12+
## Data Types ##
13+
14+
15+
16+
17+
### <a name="type-erqueue">erqueue()</a> ###
18+
19+
20+
21+
<pre><code>
22+
erqueue() = #erqueue{}
23+
</code></pre>
24+
25+
26+
<a name="index"></a>
27+
28+
## Function Index ##
29+
30+
31+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#close-1">close/1</a></td><td></td></tr><tr><td valign="top"><a href="#dump-1">dump/1</a></td><td></td></tr><tr><td valign="top"><a href="#get-1">get/1</a></td><td></td></tr><tr><td valign="top"><a href="#is_empty-1">is_empty/1</a></td><td></td></tr><tr><td valign="top"><a href="#is_full-1">is_full/1</a></td><td></td></tr><tr><td valign="top"><a href="#len-1">len/1</a></td><td></td></tr><tr><td valign="top"><a href="#new-0">new/0</a></td><td></td></tr><tr><td valign="top"><a href="#new-1">new/1</a></td><td></td></tr><tr><td valign="top"><a href="#put-2">put/2</a></td><td></td></tr></table>
32+
33+
34+
<a name="functions"></a>
35+
36+
## Function Details ##
37+
38+
<a name="close-1"></a>
39+
40+
### close/1 ###
41+
42+
43+
<pre><code>
44+
close(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; ok
45+
</code></pre>
46+
47+
<br></br>
48+
49+
50+
51+
<a name="dump-1"></a>
52+
53+
### dump/1 ###
54+
55+
56+
<pre><code>
57+
dump(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; term()
58+
</code></pre>
59+
60+
<br></br>
61+
62+
63+
64+
<a name="get-1"></a>
65+
66+
### get/1 ###
67+
68+
69+
<pre><code>
70+
get(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; {Data::term()}
71+
</code></pre>
72+
73+
<br></br>
74+
75+
76+
77+
<a name="is_empty-1"></a>
78+
79+
### is_empty/1 ###
80+
81+
82+
<pre><code>
83+
is_empty(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; boolean()
84+
</code></pre>
85+
86+
<br></br>
87+
88+
89+
90+
<a name="is_full-1"></a>
91+
92+
### is_full/1 ###
93+
94+
95+
<pre><code>
96+
is_full(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; boolean()
97+
</code></pre>
98+
99+
<br></br>
100+
101+
102+
103+
<a name="len-1"></a>
104+
105+
### len/1 ###
106+
107+
108+
<pre><code>
109+
len(Ref::<a href="#type-erqueue">erqueue()</a>) -&gt; integer()
110+
</code></pre>
111+
112+
<br></br>
113+
114+
115+
116+
<a name="new-0"></a>
117+
118+
### new/0 ###
119+
120+
121+
<pre><code>
122+
new() -&gt; {ok, <a href="#type-erqueue">erqueue()</a>} | {error, term()}
123+
</code></pre>
124+
125+
<br></br>
126+
127+
128+
129+
<a name="new-1"></a>
130+
131+
### new/1 ###
132+
133+
134+
<pre><code>
135+
new(Length::integer()) -&gt; {ok, <a href="#type-erqueue">erqueue()</a>} | {error, term()}
136+
</code></pre>
137+
138+
<br></br>
139+
140+
141+
142+
<a name="put-2"></a>
143+
144+
### put/2 ###
145+
146+
147+
<pre><code>
148+
put(Ref::<a href="#type-erqueue">erqueue()</a>, Data::any()) -&gt; true
149+
</code></pre>
150+
151+
<br></br>
152+
153+
154+

doc/overview.edoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
%% -*- erlang -*-
2+
%%
3+
%% This file is part of erqueue released under the MIT license.
4+
%% See the NOTICE for more information.
5+
6+
@copyright 2014 Stéphane Wirtel.
7+
@version 0.1.0
8+
@title erqueue - Queue using ETS.
9+
10+
@doc
11+
12+
## Description
13+
14+
The erqueue module implements a queue using the ETS module of Erlang.
15+
16+
## Usage
17+
18+
## Example
19+
20+
## Ownership and License
21+
The contributors are listed in AUTHORS. This project uses the MPL v2 license,
22+
see LICENSE.
23+
24+
erqueue uses the
25+
[C4.1 (Collective Code Construction Contract)](http://rfc.zeromq.org/spec:22)
26+
process for contributions.
27+
28+
## Examples
29+
30+
## Development
31+
32+
Under C4.1 process, you are more than welcome to help us by:
33+
34+
* join the discussion over anything from design to code style
35+
* try out and [submit issue reports](https://github.com/matrixise/erqueue/issues/new) or feature requests
36+
* pick a task in [issues](https://github.com/matrixise/erqueue) ang get it done
37+
* for the repository and have your own fixes
38+
* send us pull requests

rebar.config

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%% -*- mode: erlang -*-
2+
{lib_dirs, ["deps"]}.
3+
{erl_opts, [
4+
{i, "deps"},
5+
{src_dirs, ["src"]},
6+
debug_info
7+
]}.
8+
9+
{deps, [
10+
{edown, ".*",
11+
{git, "git://github.com/esl/edown.git", {tag, "0.4"}}}
12+
]}.
13+
14+
{edoc_opts, [
15+
{application, ["erqueue"]},
16+
{doclet, edown_doclet},
17+
{subpackages, false},
18+
{top_level_readme,
19+
{"./README.md", "http://github.com/matrixise/erqueue"}}
20+
]}.

src/erqueue.app.src

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{application, erqueue,
2+
[
3+
{description, "Queue using ETS"},
4+
{vsn, "0.1.0"},
5+
{registered, []},
6+
{applications, [
7+
kernel,
8+
stdlib
9+
]},
10+
{env, []}
11+
]}.

src/erqueue.erl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
-module(erqueue).
2+
-author("Stephane Wirtel <[email protected]>").
3+
4+
-export([
5+
new/0, new/1,
6+
put/2, get/1,
7+
len/1,
8+
is_empty/1, is_full/1,
9+
dump/1,
10+
close/1
11+
]).
12+
13+
-record(erqueue, {
14+
table,
15+
length = nil :: integer()
16+
}).
17+
18+
-type erqueue() :: #erqueue{}.
19+
20+
-spec new() -> {ok, erqueue()} | {error, term()}.
21+
new() ->
22+
new(nil).
23+
24+
-spec new(Length :: integer()) -> {ok, erqueue()} | {error, term()}.
25+
new(Length) ->
26+
TableID = ets:new(queue, [public, ordered_set]),
27+
#erqueue{table=TableID, length=Length}.
28+
29+
-spec put(Ref :: erqueue(), Data :: any()) -> true.
30+
put(#erqueue{table=TableID}=_Ref, Data) ->
31+
Key = case ets:last(TableID) of
32+
'$end_of_table' -> 0;
33+
Counter -> Counter + 1
34+
end,
35+
36+
true = ets:insert(TableID, {Key, Data}),
37+
ok.
38+
39+
-spec get(Ref :: erqueue()) -> {Data :: term()}.
40+
get(#erqueue{table=TableID}=_Ref) ->
41+
case ets:first(TableID) of
42+
'$end_of_table' -> empty;
43+
First ->
44+
[{_, Item}] = ets:lookup(TableID, First),
45+
true = ets:delete(TableID, First),
46+
{value, Item}
47+
end.
48+
49+
-spec len(Ref :: erqueue()) -> integer().
50+
len(#erqueue{table=TableID}=_Ref) ->
51+
ets:info(TableID, size).
52+
53+
-spec is_empty(Ref :: erqueue()) -> boolean().
54+
is_empty(Ref) ->
55+
len(Ref) =:= 0.
56+
57+
-spec is_full(Ref :: erqueue()) -> boolean().
58+
is_full(#erqueue{length=nil}=_Ref) ->
59+
no_maximum;
60+
61+
is_full(#erqueue{length=MaxLength}=Ref) ->
62+
len(Ref) =:= MaxLength.
63+
64+
-spec dump(Ref :: erqueue()) -> term().
65+
dump(#erqueue{table=TableID}=_Ref) ->
66+
ets:tab2list(TableID).
67+
68+
-spec close(Ref :: erqueue()) -> ok.
69+
close(#erqueue{table=TableID}=_Ref) ->
70+
true = ets:delete(TableID),
71+
ok.
72+
73+

0 commit comments

Comments
 (0)