Commit a6350ef8 authored by kolusask's avatar kolusask
Browse files

Create HashGraphS and it's Map and Set

parent feeeb410
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -2,6 +2,7 @@


#include "HashGraphV1/HashGraphV1.h"
#include "HashGraphV1/HashGraphV1.h"
#include "HashGraphV2/HashGraphV2.h"
#include "HashGraphV2/HashGraphV2.h"
#include "HashGraphS/HashGraphS.h"


#include <TNL/Containers/Array.h>
#include <TNL/Containers/Array.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Host.h>
+3 −0
Original line number Original line Diff line number Diff line
@@ -26,3 +26,6 @@ using HashGraphV1Map = HashGraphMap<HashGraphV1, K, V, Device>;


// template<typename K, typename V, typename Device>
// template<typename K, typename V, typename Device>
// using HashGraphV2Map = HashGraphMap<HashGraphV2, K, V, Device>;
// using HashGraphV2Map = HashGraphMap<HashGraphV2, K, V, Device>;

template<typename K, typename V, typename Device>
using HashGraphSMap = HashGraphMap<HashGraphS, K, V, Device>;
+48 −0
Original line number Original line Diff line number Diff line
#pragma once

#include "../../HashFunction.h"
#include "HashGraphSView.h"

#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/Vector.h>

#include <vector>

using namespace TNL::Algorithms::Segments;
using namespace TNL::Containers;

// template<typename Item, typename Key, typename Device>
// class HashGraphV1View;

template<typename Item, typename Key, typename Device>
class HashGraphS {
    using ViewType = HashGraphSView<Item, Key, Device>;
    using Self = HashGraphS<Item, Key, Device>;
    friend ViewType::HashGraphSView(Self&, const typename Array<Item, Device>::ConstViewType,
                                    ArrayView<int, Device>);

  public:
    void debug_print() const {
      std::cout << "CONTENT" << std::endl;
      std::cout << m_content << std::endl;
      std::cout << "ITEMS" << std::endl;
      std::cout << m_items << std::endl;
      std::cout << "OFFSET" << std::endl;
      std::cout << m_offset << std::endl;
      
    }
    int duplicates() const;

  protected:
    HashGraphS(const Array<Item, Device>& items);
    bool find(const Key& key, ArrayView<Item, Device> item) const;

  private:
    Array<Item> m_table;
    Vector<int, Device> m_segmentSizes;
    CSR<Device, int> m_csr;
};


#include "HashGraphS.hpp"
+25 −0
Original line number Original line Diff line number Diff line
#pragma once

#include "HashGraphS.h"

#include "HashGraphSView.h"

#include "../../RandomIntGenerator.h"

#include <TNL/Containers/Array.h>


template<typename Item, typename Key, typename Device>
HashGraphS<Item, Key, Device>::HashGraphS(const Array<Item, Device>& items) :
            m_view(*this, items.getConstView()) {}

template<typename Item, typename Key, typename Device>
int HashGraphS<Item, Key, Device>::duplicates() const {
    // TODO
    return -1;
}

template<typename Item, typename Key, typename Device>
bool HashGraphS<Item, Key, Device>::find(const Key& key, ArrayView<Item, Device> item) const {
    return m_view->find(key, item);
}
+43 −0
Original line number Original line Diff line number Diff line
#pragma once

#include "HashGraphS.h"

#include "../../HashFunction.h"

#include <TNL/Algorithms/Segments/CSRView.h>
#include <TNL/Containers/ArrayView.h>
#include <TNL/Containers/VectorView.h>

#include <vector>


using namespace TNL::Algorithms::Segments;
using namespace TNL::Containers;

template<typename Item, typename Key, typename Device>
class HashGraphS;

template<typename Item, typename Key, typename Device>
class HashGraphSView {
    using TableType = HashGraphS<Item, Key, Device>;

  public:
    HashGraphSView(TableType& table,
                   const typename Array<Item, Device>::ConstViewType items);
    ~HashGraphSView();
    int duplicates() const;

    bool find(const Key& key, ArrayView<Item, Device> item) const;

    void build();

    void fill_offset(const ArrayView<int, Device>& counter);

  private:
    ArrayView<Item> m_table;
    CSRView<Device, int> m_csr;
    VectorView<int, Device> m_segmentsSizes;
};


#include "HashGraphSView.hpp"
Loading