1// Copyright 2013 Google Inc. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14// 15// Block split point selection utilities. 16 17#ifndef BROTLI_ENC_BLOCK_SPLITTER_H_ 18#define BROTLI_ENC_BLOCK_SPLITTER_H_ 19 20#include <stddef.h> 21#include <stdint.h> 22#include <string.h> 23#include <vector> 24#include <utility> 25 26#include "./command.h" 27 28namespace brotli { 29 30struct BlockSplit { 31 int num_types_; 32 std::vector<uint8_t> types_; 33 std::vector<int> type_codes_; 34 std::vector<int> lengths_; 35}; 36 37struct BlockSplitIterator { 38 explicit BlockSplitIterator(const BlockSplit& split) 39 : split_(split), idx_(0), type_(0), length_(0) { 40 if (!split.lengths_.empty()) { 41 length_ = split.lengths_[0]; 42 } 43 } 44 45 void Next() { 46 if (length_ == 0) { 47 ++idx_; 48 type_ = split_.types_[idx_]; 49 length_ = split_.lengths_[idx_]; 50 } 51 --length_; 52 } 53 54 const BlockSplit& split_; 55 int idx_; 56 int type_; 57 int length_; 58}; 59 60void CopyLiteralsToByteArray(const std::vector<Command>& cmds, 61 const uint8_t* data, 62 std::vector<uint8_t>* literals); 63 64void SplitBlock(const std::vector<Command>& cmds, 65 const uint8_t* data, 66 BlockSplit* literal_split, 67 BlockSplit* insert_and_copy_split, 68 BlockSplit* dist_split); 69 70void SplitBlockByTotalLength(const std::vector<Command>& all_commands, 71 int input_size, 72 int target_length, 73 std::vector<std::vector<Command> >* blocks); 74 75} // namespace brotli 76 77#endif // BROTLI_ENC_BLOCK_SPLITTER_H_ 78