// genDElement - An abstract data element library
// Copyright (C) 2013-2026 Eric Bechet, Frederic Duboeuf
//
// See the LICENSE file for license information.
// Please report all bugs and problems to <bechet@cadxfem.org> or <duboeuf@outlook.com>.
//
// Initial design: Frederic Duboeuf (rev.1511)


#ifndef _GEN_DELEMENT_KEY_H_
#define _GEN_DELEMENT_KEY_H_

#include <vector>
#include <iostream>

// the key of an element is an ordered vector of the vertex numbers
class Key
{
protected :
  std::vector<int> vNums;
public :
  Key() : vNums(0) {}
  Key(std::vector<int> &vNums_) : vNums(vNums_) {}
  void clear() {vNums.clear();}
  int size() const {return vNums.size();}
  int get(int i) const {return vNums[i];}
  void set(const std::vector<int> &vNums_) {vNums=vNums_;}
  bool operator<(const Key &other) const
  {
    if(vNums.size() < other.vNums.size()) return true;
    if(vNums.size() > other.vNums.size()) return false;
    for (int i=0; i<vNums.size(); ++i)
    {
      if(vNums[i] < other.vNums[i]) return true;
      if(vNums[i] > other.vNums[i]) return false;
    }
    return false;
  }
  bool operator==(const Key &other) const
  {
    if(vNums.size() != other.vNums.size()) return false;
    for (int i=0; i<vNums.size(); ++i)
      if(vNums[i] != other.vNums[i]) return false;
    return true;
  }
  friend std::ostream & operator<<(std::ostream &os, const Key &key)
  {
    std::streamsize width = os.width();
    os.width(width); os <<"";
    os << "key :";
    for (int i=0; i<key.vNums.size(); ++i)
      std::cout << " " << key.vNums[i];
    os << "\n";
    return os;
  }
};

#endif // _GEN_DELEMENT_KEY_H_
