From 6390f54f9f42d6145fa96d17b2a772c413cc11cb Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 6 Jul 2010 18:50:24 +0000 Subject: [PATCH] VarInt: added method getLengthOfVarInt(). --- dbms/include/DB/IO/VarInt.h | 3 +++ dbms/src/IO/VarInt.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/dbms/include/DB/IO/VarInt.h b/dbms/include/DB/IO/VarInt.h index 8e91925ede7..dd5590b827e 100644 --- a/dbms/include/DB/IO/VarInt.h +++ b/dbms/include/DB/IO/VarInt.h @@ -23,6 +23,9 @@ void readVarUInt(UInt64 & x, ReadBuffer & istr); /** Получить длину UInt64 в формате VarUInt */ size_t getLengthOfVarUInt(UInt64 x); +/** Получить длину Int64 в формате VarInt */ +size_t getLengthOfVarInt(Int64 x); + /** Записать Int64 в формате переменной длины (base128) */ template diff --git a/dbms/src/IO/VarInt.cpp b/dbms/src/IO/VarInt.cpp index 50a1e0fa863..7350bd71bc4 100644 --- a/dbms/src/IO/VarInt.cpp +++ b/dbms/src/IO/VarInt.cpp @@ -287,4 +287,10 @@ size_t getLengthOfVarUInt(UInt64 x) } +size_t getLengthOfVarInt(Int64 x) +{ + return getLengthOfVarUInt(static_cast((x << 1) ^ (x >> 63))); +} + + }