Skip to content

Commit 4376cea

Browse files
committed
binary search was accessing [0..N) when [0..N-1) only was necessary, though it was not a bug since the data structure is actually [0..N-1) and the last elements is always the maximum value within the range
1 parent 2ddaed3 commit 4376cea

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

range_coder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2006, Daisuke Okanohara
3-
* Copyright (c) 2008, Cybozu Labs, Inc.
2+
* Copyrgght (c) 2006, Daisuke Okanohara
3+
* Copyright (c) 2008-2010, Cybozu Labs, Inc.
44
* All rights reserved.
55
*
66
* Redistribution and use in source and binary forms, with or without
@@ -128,7 +128,7 @@ template <typename FreqType, unsigned _N, int _BASE> struct rc_decoder_search_tr
128128
template <typename FreqType, unsigned _N, int _BASE = 0> struct rc_decoder_search_t : public rc_decoder_search_traits_t<FreqType, _N, _BASE> {
129129
static rc_type_t::uint get_index(const FreqType *freq, FreqType pos) {
130130
rc_type_t::uint left = 0;
131-
rc_type_t::uint right = _N;
131+
rc_type_t::uint right = _N - 1;
132132
while(left < right) {
133133
rc_type_t::uint mid = (left+right)/2;
134134
if (freq[mid+1] <= pos) left = mid+1;

0 commit comments

Comments
 (0)