0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellListScannerBuffer.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #include "Common/Compat.h"
30 
31 #include <cassert>
32 
33 #include "CellListScannerBuffer.h"
34 
35 using namespace Hypertable;
36 using namespace std;
37 
38 
40  : CellListScanner(scan_ctx.get()), m_scan_context(scan_ctx), m_arena(524288) {
41 }
42 
43 void CellListScannerBuffer::add(const SerializedKey key, const ByteString value) {
44  uint8_t *key_data, *value_data;
45  size_t key_length, value_length;
46 
47  assert(!m_initialized_for_scan);
48 
49  key_length = key.length();
50  key_data = m_arena.alloc(key_length);
51  memcpy(key_data, key.ptr, key_length);
52 
53  value_length = value.length();
54  value_data = m_arena.alloc(value_length);
55  memcpy(value_data, value.ptr, value_length);
56 
57  m_cells.push_back( make_pair(SerializedKey(key_data), ByteString(value_data)) );
58 
59 }
60 
64  if (m_iter != m_cells.end())
65  ++m_iter;
66 }
67 
71  if (m_iter == m_cells.end())
72  return false;
73  key.load(m_iter->first);
74  value = m_iter->second;
75  return true;
76 }
77 
78 
79 // PRIVATE methods
80 
81 
83  LtKeyValueT swo;
84  std::sort(m_cells.begin(), m_cells.end(), swo);
85  m_iter = m_cells.begin();
86  m_initialized_for_scan = true;
87 }
88 
KeyValueVectorT m_cells
Buffer (array) of cells to be returned.
STL Strict Weak Ordering for KeyValueT.
STL namespace.
Declarations for CellListScannerBuffer.
CharT * alloc(size_t sz)
Allocate sz bytes.
Definition: PageArena.h:216
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
void initialize_for_scan()
Sorts cells in preparation for scan.
ByteArena m_arena
Memory arena to hold serialized keys and values.
void add(const SerializedKey key, const ByteString value)
Adds a key/value pair to the buffer.
Compatibility Macros for C/C++.
bool load(const SerializedKey &key)
Parses the opaque key and loads the components into the member variables.
Definition: Key.cc:158
T get(const String &name)
Retrieves a configuration value.
Definition: Config.h:82
size_t length() const
Retrieves the length of the serialized string.
Definition: ByteString.h:62
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
bool m_initialized_for_scan
Flag indicating if initialize_for_scan has been called.
Hypertable definitions
CellListScannerBuffer(ScanContextPtr &scan_ctx)
Constructor.
Provides access to internal components of opaque key.
Definition: Key.h:40
virtual bool get(Key &key, ByteString &value)
KeyValueVectorT::iterator m_iter
Iterator pointing to next cell in m_cells to be returned.
std::shared_ptr< ScanContext > ScanContextPtr
Definition: ScanContext.h:169