/*                                                                                   
 * Copyright (C) 2015 by the University of Southern California                       
 * $Id: safe_map.hh 23936 2015-05-11 23:52:39Z liangzhu $
 *                                                                                   
 * This program is free software; you can redistribute it and/or                     
 * modify it under the terms of the GNU General Public License,                      
 * version 2, as published by the Free Software Foundation.                          
 *                                                                                   
 * This program is distributed in the hope that it will be useful,                   
 * but WITHOUT ANY WARRANTY; without even the implied warranty of                    
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                     
 * GNU General Public License for more details.                                      
 *                                                                                   
 * You should have received a copy of the GNU General Public License along           
 * with this program; if not, write to the Free Software Foundation, Inc.,           
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.                           
 *                                                                                   
 */

#ifndef SAFE_MAP_HH
#define SAFE_MAP_HH

#include <mutex>
#include <unordered_map>

template <typename T, typename S>
class safe_map {
public:
  safe_map();
  ~safe_map();
  void push(T x, S y);
  bool find(T x); //find by key
  void erase(T x);
  bool empty();
  S get(T x);
  S pop_second();
  T pop_first();

private:
  std::unordered_map<T, S> m;
  std::mutex mtx;
};

#endif //SAFE_MAP_HH
