| 1 | /*
 | 
| 2 |  * Souffle - A Datalog Compiler
 | 
| 3 |  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 | 
| 4 |  * Licensed under the Universal Permissive License v 1.0 as shown at:
 | 
| 5 |  * - https://opensource.org/licenses/UPL
 | 
| 6 |  * - <souffle root>/licenses/SOUFFLE-UPL.txt
 | 
| 7 |  */
 | 
| 8 | 
 | 
| 9 | /************************************************************************
 | 
| 10 |  *
 | 
| 11 |  * @file RecordTable.h
 | 
| 12 |  *
 | 
| 13 |  * Data container implementing a map between records and their references.
 | 
| 14 |  * Records are separated by arity, i.e., stored in different RecordMaps.
 | 
| 15 |  *
 | 
| 16 |  ***********************************************************************/
 | 
| 17 | 
 | 
| 18 | #pragma once
 | 
| 19 | 
 | 
| 20 | #include "souffle/RamTypes.h"
 | 
| 21 | #include "souffle/utility/span.h"
 | 
| 22 | #include <initializer_list>
 | 
| 23 | 
 | 
| 24 | namespace souffle {
 | 
| 25 | 
 | 
| 26 | /** The interface of any Record Table. */
 | 
| 27 | class RecordTable {
 | 
| 28 | public:
 | 
| 29 |     virtual ~RecordTable() {}
 | 
| 30 | 
 | 
| 31 |     virtual void setNumLanes(const std::size_t NumLanes) = 0;
 | 
| 32 | 
 | 
| 33 |     virtual RamDomain pack(const RamDomain* Tuple, const std::size_t Arity) = 0;
 | 
| 34 | 
 | 
| 35 |     virtual RamDomain pack(const std::initializer_list<RamDomain>& List) = 0;
 | 
| 36 | 
 | 
| 37 |     virtual const RamDomain* unpack(const RamDomain Ref, const std::size_t Arity) const = 0;
 | 
| 38 | };
 | 
| 39 | 
 | 
| 40 | /** @brief helper to convert tuple to record reference for the synthesiser */
 | 
| 41 | template <class RecordTableT, std::size_t Arity>
 | 
| 42 | RamDomain pack(RecordTableT&& recordTab, Tuple<RamDomain, Arity> const& tuple) {
 | 
| 43 |     return recordTab.pack(tuple.data(), Arity);
 | 
| 44 | }
 | 
| 45 | 
 | 
| 46 | /** @brief helper to convert tuple to record reference for the synthesiser */
 | 
| 47 | template <class RecordTableT, std::size_t Arity>
 | 
| 48 | RamDomain pack(RecordTableT&& recordTab, span<const RamDomain, Arity> tuple) {
 | 
| 49 |     return recordTab.pack(tuple.data(), Arity);
 | 
| 50 | }
 | 
| 51 | 
 | 
| 52 | /** @brief helper to pack using an initialization-list of RamDomain values. */
 | 
| 53 | template <class RecordTableT>
 | 
| 54 | RamDomain pack(RecordTableT&& recordTab, const std::initializer_list<RamDomain>&& initlist) {
 | 
| 55 |     return recordTab.pack(std::data(initlist), initlist.size());
 | 
| 56 | }
 | 
| 57 | 
 | 
| 58 | }  // namespace souffle
 |