Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
e4b2657e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4b2657e
编写于
12月 14, 2012
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: fixed VarUInt for numbers with highest significant bit set [#CONV-2944].
上级
a8cf5508
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
54 deletion
+74
-54
dbms/src/IO/VarInt.cpp
dbms/src/IO/VarInt.cpp
+54
-54
dbms/src/IO/tests/var_uint.cpp
dbms/src/IO/tests/var_uint.cpp
+20
-0
未找到文件。
dbms/src/IO/VarInt.cpp
浏览文件 @
e4b2657e
...
...
@@ -17,31 +17,31 @@ void writeVarUInt(UInt64 x, std::ostream & ostr)
{
char
buf
[
9
];
buf
[
0
]
=
static_cast
<
Poco
::
UInt8
>
(
x
|
0x80
);
buf
[
0
]
=
static_cast
<
UInt8
>
(
x
|
0x80
);
if
(
x
>=
(
1ULL
<<
7
))
{
buf
[
1
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
7
)
|
0x80
);
buf
[
1
]
=
static_cast
<
UInt8
>
((
x
>>
7
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
14
))
{
buf
[
2
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
14
)
|
0x80
);
buf
[
2
]
=
static_cast
<
UInt8
>
((
x
>>
14
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
21
))
{
buf
[
3
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
21
)
|
0x80
);
buf
[
3
]
=
static_cast
<
UInt8
>
((
x
>>
21
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
28
))
{
buf
[
4
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
28
)
|
0x80
);
buf
[
4
]
=
static_cast
<
UInt8
>
((
x
>>
28
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
35
))
{
buf
[
5
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
35
)
|
0x80
);
buf
[
5
]
=
static_cast
<
UInt8
>
((
x
>>
35
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
42
))
{
buf
[
6
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
42
)
|
0x80
);
buf
[
6
]
=
static_cast
<
UInt8
>
((
x
>>
42
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
49
))
{
buf
[
7
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
49
)
|
0x80
);
buf
[
7
]
=
static_cast
<
UInt8
>
((
x
>>
49
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
56
))
{
buf
[
8
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
56
)
|
0x80
);
buf
[
8
]
=
static_cast
<
UInt8
>
(
x
>>
56
);
ostr
.
write
(
buf
,
9
);
}
else
...
...
@@ -99,39 +99,39 @@ void readVarUInt(UInt64 & x, std::istream & istr)
int
byte
;
byte
=
istr
.
get
();
x
=
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
;
x
=
static_cast
<
UInt64
>
(
byte
)
&
0x7F
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
7
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
7
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
14
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
14
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
21
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
21
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
28
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
28
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
35
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
35
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
42
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
42
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
49
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
49
;
if
(
byte
&
0x80
)
{
byte
=
istr
.
get
();
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
56
;
x
|=
static_cast
<
UInt64
>
(
byte
)
<<
56
;
}
}
}
...
...
@@ -147,31 +147,31 @@ void writeVarUInt(UInt64 x, WriteBuffer & ostr)
{
char
buf
[
9
];
buf
[
0
]
=
static_cast
<
Poco
::
UInt8
>
(
x
|
0x80
);
buf
[
0
]
=
static_cast
<
UInt8
>
(
x
|
0x80
);
if
(
x
>=
(
1ULL
<<
7
))
{
buf
[
1
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
7
)
|
0x80
);
buf
[
1
]
=
static_cast
<
UInt8
>
((
x
>>
7
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
14
))
{
buf
[
2
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
14
)
|
0x80
);
buf
[
2
]
=
static_cast
<
UInt8
>
((
x
>>
14
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
21
))
{
buf
[
3
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
21
)
|
0x80
);
buf
[
3
]
=
static_cast
<
UInt8
>
((
x
>>
21
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
28
))
{
buf
[
4
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
28
)
|
0x80
);
buf
[
4
]
=
static_cast
<
UInt8
>
((
x
>>
28
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
35
))
{
buf
[
5
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
35
)
|
0x80
);
buf
[
5
]
=
static_cast
<
UInt8
>
((
x
>>
35
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
42
))
{
buf
[
6
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
42
)
|
0x80
);
buf
[
6
]
=
static_cast
<
UInt8
>
((
x
>>
42
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
49
))
{
buf
[
7
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
49
)
|
0x80
);
buf
[
7
]
=
static_cast
<
UInt8
>
((
x
>>
49
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
56
))
{
buf
[
8
]
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
56
)
|
0x80
);
buf
[
8
]
=
static_cast
<
UInt8
>
(
x
>>
56
);
ostr
.
write
(
buf
,
9
);
}
else
...
...
@@ -229,39 +229,39 @@ void readVarUInt(UInt64 & x, ReadBuffer & istr)
char
byte
;
readChar
(
byte
,
istr
);
x
=
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
;
x
=
static_cast
<
UInt64
>
(
byte
)
&
0x7F
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
7
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
7
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
14
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
14
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
21
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
21
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
28
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
28
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
35
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
35
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
42
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
42
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
49
;
x
|=
(
static_cast
<
UInt64
>
(
byte
)
&
0x7F
)
<<
49
;
if
(
byte
&
0x80
)
{
readChar
(
byte
,
istr
);
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
byte
)
&
0x7F
)
<<
56
;
x
|=
static_cast
<
UInt64
>
(
byte
)
<<
56
;
}
}
}
...
...
@@ -275,31 +275,31 @@ void readVarUInt(UInt64 & x, ReadBuffer & istr)
char
*
writeVarUInt
(
UInt64
x
,
char
*
ostr
)
{
*
ostr
=
static_cast
<
Poco
::
UInt8
>
(
x
|
0x80
);
*
ostr
=
static_cast
<
UInt8
>
(
x
|
0x80
);
if
(
x
>=
(
1ULL
<<
7
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
7
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
7
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
14
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
14
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
14
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
21
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
21
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
21
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
28
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
28
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
28
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
35
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
35
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
35
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
42
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
42
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
42
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
49
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
49
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
((
x
>>
49
)
|
0x80
);
if
(
x
>=
(
1ULL
<<
56
))
{
*++
ostr
=
static_cast
<
Poco
::
UInt8
>
((
x
>>
56
)
|
0x80
);
*++
ostr
=
static_cast
<
UInt8
>
(
x
>>
56
);
}
else
*
ostr
&=
0x7F
;
...
...
@@ -333,31 +333,31 @@ const char * readVarUInt(UInt64 & x, const char * istr, size_t size)
{
const
char
*
end
=
istr
+
size
;
x
=
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
;
x
=
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
7
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
7
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
14
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
14
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
21
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
21
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
28
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
28
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
35
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
35
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
42
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
42
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
49
;
x
|=
(
static_cast
<
UInt64
>
(
*
istr
)
&
0x7F
)
<<
49
;
if
(
*
istr
&
0x80
&&
++
istr
<
end
)
{
x
|=
(
static_cast
<
Poco
::
UInt64
>
(
*
istr
)
&
0x7F
)
<<
56
;
x
|=
static_cast
<
UInt64
>
(
*
istr
)
<<
56
;
}
}
}
...
...
dbms/src/IO/tests/var_uint.cpp
浏览文件 @
e4b2657e
...
...
@@ -2,6 +2,8 @@
#include <iostream>
#include <DB/IO/VarInt.h>
#include <DB/IO/WriteBufferFromString.h>
#include <DB/IO/ReadBufferFromString.h>
#include <Poco/NumberParser.h>
#include <Poco/HexBinaryEncoder.h>
...
...
@@ -19,6 +21,24 @@ int main(int argc, char ** argv)
Poco
::
HexBinaryEncoder
hex
(
std
::
cout
);
DB
::
writeVarUInt
(
x
,
hex
);
std
::
cout
<<
std
::
endl
;
std
::
string
s
;
{
DB
::
WriteBufferFromString
wb
(
s
);
DB
::
writeVarUInt
(
x
,
wb
);
wb
.
next
();
}
hex
<<
s
;
std
::
cout
<<
std
::
endl
;
DB
::
UInt64
y
=
0
;
DB
::
ReadBufferFromString
rb
(
s
);
DB
::
readVarUInt
(
y
,
rb
);
std
::
cerr
<<
"x: "
<<
x
<<
", y: "
<<
y
<<
std
::
endl
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录