Skip to content

Instantly share code, notes, and snippets.

@Damienkatz
Created June 12, 2013 23:08
Show Gist options
  • Save Damienkatz/5769917 to your computer and use it in GitHub Desktop.
Save Damienkatz/5769917 to your computer and use it in GitHub Desktop.
// Macro needed for llvm/ADT/ImmutableSet.h
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#define UNDO_STDC_LIMIT_MACROS_SRC_VBUCKET_BYSEQ_H_
#endif
// Macro needed for llvm/ADT/ImmutableSet.h
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#define UNDO_STDC_CONSTANT_MACROS_SRC_VBUCKET_BYSEQ_H_
#endif
#include "llvm/ADT/ImmutableMap.h"
#include <cstdio>
/**
* ImutKeyValueInfo implementation to allow queued_item to be stored in
* llvm::ImmutableMap
*/
class QiImutKeyValueInfo :
public llvm::ImutKeyValueInfo<int, int> {
public:
static inline void Profile(llvm::FoldingSetNodeID& ID, value_type_ref V) {
ID.AddInteger(V.first);
ID.AddInteger(V.second);
}
};
typedef llvm::ImmutableMap<int,
int,
QiImutKeyValueInfo> mymap;
void dump(mymap& map) {
for (mymap::iterator it = map.begin();
it != map.end();
++it) {
printf("%i, %i", it->first, it->second);
}
}
int main(int argc, char *argv[]) {
mymap::Factory factory(false);
mymap map = factory.getEmptyMap();
map = factory.add(map, 1, 2);
map = factory.add(map, 2, 2);
map = factory.add(map, 3, 2);
map = factory.add(map, 4, 2);
map = factory.add(map, 5, 2);
dump(map);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment