Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
732cde3a
A
ascs
项目概览
youngwolf
/
ascs
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ascs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
732cde3a
编写于
5月 17, 2019
作者:
Y
yang li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A small refactoring on class queue.
上级
4c6cb48d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
29 deletion
+33
-29
include/ascs/container.h
include/ascs/container.h
+33
-29
未找到文件。
include/ascs/container.h
浏览文件 @
732cde3a
...
...
@@ -67,20 +67,20 @@ public:
using
typename
Container
::
const_reference
;
using
Container
::
empty
;
queue
()
:
buff
_size
(
0
)
{}
queue
(
size_t
capacity
)
:
Container
(
capacity
),
buff
_size
(
0
)
{}
queue
()
:
total
_size
(
0
)
{}
queue
(
size_t
capacity
)
:
Container
(
capacity
),
total
_size
(
0
)
{}
//thread safe
bool
is_thread_safe
()
const
{
return
Lockable
::
is_lockable
();}
size_t
size_in_byte
()
const
{
return
buff
_size
;}
void
clear
()
{
typename
Lockable
::
lock_guard
lock
(
*
this
);
Container
::
clear
();
buff
_size
=
0
;}
size_t
size_in_byte
()
const
{
return
total
_size
;}
void
clear
()
{
typename
Lockable
::
lock_guard
lock
(
*
this
);
Container
::
clear
();
total
_size
=
0
;}
void
swap
(
Container
&
can
)
{
auto
size_in_byte
=
ascs
::
get_size_in_byte
(
can
);
typename
Lockable
::
lock_guard
lock
(
*
this
);
Container
::
swap
(
can
);
buff
_size
=
size_in_byte
;
total
_size
=
size_in_byte
;
}
template
<
typename
T
>
bool
enqueue
(
T
&&
item
)
{
typename
Lockable
::
lock_guard
lock
(
*
this
);
return
enqueue_
(
std
::
forward
<
T
>
(
item
));}
...
...
@@ -97,9 +97,9 @@ public:
{
try
{
auto
s
=
item
.
size
();
auto
s
ize
=
item
.
size
();
this
->
emplace_back
(
std
::
forward
<
T
>
(
item
));
buff_size
+=
s
;
total_size
+=
size
;
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -116,50 +116,39 @@ public:
size_in_byte
=
ascs
::
get_size_in_byte
(
src
);
this
->
splice
(
this
->
end
(),
src
);
buff
_size
+=
size_in_byte
;
total
_size
+=
size_in_byte
;
}
bool
try_dequeue_
(
reference
item
)
{
if
(
this
->
empty
())
return
false
;
item
.
swap
(
this
->
front
());
this
->
pop_front
();
buff
_size
-=
item
.
size
();
return
true
;}
bool
try_dequeue_
(
reference
item
)
{
if
(
this
->
empty
())
return
false
;
item
.
swap
(
this
->
front
());
this
->
pop_front
();
total
_size
-=
item
.
size
();
return
true
;}
void
move_items_out_
(
Container
&
dest
,
size_t
max_item_num
=
-
1
)
{
if
((
size_t
)
-
1
==
max_item_num
)
{
dest
.
splice
(
std
::
end
(
dest
),
*
this
);
buff
_size
=
0
;
total
_size
=
0
;
}
else
if
(
max_item_num
>
0
)
{
size_t
s
=
0
,
index
=
0
;
size_t
s
ize
=
0
,
index
=
0
;
auto
end_iter
=
this
->
begin
();
do_something_to_one_
([
&
](
const_reference
item
)
{
if
(
++
index
>
max_item_num
)
return
true
;
s
+=
item
.
size
();
++
end_iter
;
return
false
;});
do_something_to_one_
([
&
](
const_reference
item
)
{
if
(
++
index
>
max_item_num
)
return
true
;
s
ize
+=
item
.
size
();
++
end_iter
;
return
false
;});
if
(
end_iter
==
this
->
end
())
dest
.
splice
(
std
::
end
(
dest
),
*
this
);
else
dest
.
splice
(
std
::
end
(
dest
),
*
this
,
this
->
begin
(),
end_iter
);
buff_size
-=
s
;
move_items_out
(
dest
,
end_iter
,
size
);
}
}
void
move_items_out_
(
size_t
max_size_in_byte
,
Container
&
dest
)
{
if
((
size_t
)
-
1
==
max_size_in_byte
)
{
dest
.
splice
(
std
::
end
(
dest
),
*
this
);
buff_size
=
0
;
}
move_items_out_
(
dest
);
else
{
size_t
s
=
0
;
size_t
s
ize
=
0
;
auto
end_iter
=
this
->
begin
();
do_something_to_one_
([
&
](
const_reference
item
)
{
s
+=
item
.
size
();
++
end_iter
;
if
(
s
>=
max_size_in_byte
)
return
true
;
return
false
;});
do_something_to_one_
([
&
](
const_reference
item
)
{
s
ize
+=
item
.
size
();
++
end_iter
;
if
(
size
>=
max_size_in_byte
)
return
true
;
return
false
;});
if
(
end_iter
==
this
->
end
())
dest
.
splice
(
std
::
end
(
dest
),
*
this
);
else
dest
.
splice
(
std
::
end
(
dest
),
*
this
,
this
->
begin
(),
end_iter
);
buff_size
-=
s
;
move_items_out
(
dest
,
end_iter
,
size
);
}
}
...
...
@@ -174,8 +163,23 @@ public:
void
do_something_to_one_
(
const
_Predicate
&
__pred
)
const
{
for
(
auto
iter
=
this
->
begin
();
iter
!=
this
->
end
();
++
iter
)
if
(
__pred
(
*
iter
))
break
;}
//not thread safe
protected:
#if __GNUC__ > 4 || __GNUC_MINOR__ > 8
void
move_items_out
(
Container
&
dest
,
typename
Container
::
const_iterator
end_iter
,
size_t
size
)
#else
void
move_items_out
(
Container
&
dest
,
typename
Container
::
iterator
end_iter
,
size_t
size
)
//just satisfy old gcc compilers (before gcc 4.9)
#endif
{
if
(
end_iter
==
this
->
end
())
dest
.
splice
(
std
::
end
(
dest
),
*
this
);
else
dest
.
splice
(
std
::
end
(
dest
),
*
this
,
this
->
begin
(),
end_iter
);
total_size
-=
size
;
}
private:
size_t
buff_size
;
//in use
size_t
total_size
;
};
//ascs requires that queue must take one and only one template argument
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录