Skip to content

Instantly share code, notes, and snippets.

struct Foo {
vec: ~[int]
}
impl Foo {
fn iter(&self) -> ?? {
self.vec.iter()
}
}
// This is the initial idea: a graph structure that is a hash containing a vector of target node and edge properties
// Doesn’t compile with
// src/graph.rs:56:32: 56:37 error: cannot move out of dereference of `&`-pointer
// src/graph.rs:56 Some(list) => for &(n,e) in list.iter() {
trait Graph<Node, Edge> {
fn children(&self, &Node, |Node, Edge| -> ()); // iterate on outgoing edges
}
impl<N:Hash+Eq,E> Graph<N,E> for HashMap<N, ~[(N,E)]> {
trait GraphAlgorithm<Node, Edge> {
fn dfs_rec(&self, source: &Node, visitor: |&Node| -> (), visited: &mut HashSet<&Node>);
}
impl<'a, Node:Hash+Eq, Edge> GraphAlgorithm<Node, Edge> for &'a Graph<Node, Edge> {
fn dfs_rec<'a>(&self, source: &Node, visitor: |&Node| -> (), visited: &'a mut HashSet<&Node>) {
visitor(source);
self.children(source, |target,_| {
if !visited.contains(&target) {
// visited.insert(target);
/* Compile and run
*
* g++ -Wall -O2 --std=c++11 max_weight.cc -o max_weight
* clang++ -Wall -O2 --std=c++11 max_weight.cc -o max_weight
*
* To run the tests:
* ./max_weight
*
* To test your own input
* ./max_weight 1 5 12 0 42 33 1
grabougrabou
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_push_back_actor.hpp>
#include <iostream>
using namespace BOOST_SPIRIT_CLASSIC_NS;
int main(int, char**)
{
@Tristramg
Tristramg / main.cc
Created November 10, 2010 10:27 — forked from anonymous/main.cc
/*
* main.cc
*
* Created on: Nov 9, 2010
* Author: julien
*/
#include <iostream>
#include "memory/trail_impl.hh"
#include "memory/restorable_impl.hh"
#include <vector>
class Foo {
template<class Type> std::vector<Type> get(){ throw "vtff";}
template<> std::vector<int> get(){std::vector<int> val; val.push_back(42); return val;}
}
void main(int, char**) {
Foo f;
std::cout << f.get<int>()[0] << std::endl;
#pragma once
/** Allows to relationalish queries on any datastructure stored in std::vector
*
* We use vocabulary form relationnal databases, however the querying and indexing possibilities
* are rather poor compared to a real DB
*
* The user must define the datastructures he want to use: struct City {std::string name; int population;}
* and store them in std::vectors
*
for i in range(6, len(l) - 1):
current_node = nodes_map[l[0]][l[i]]
self.session.add(PT_Edge(prev_stop, current_node, 0, departure, departure + tps_moyen, 0, 'Metro', str(lines_count)))
prev_stop = current_node