Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-emplace.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32# include <iostream>
33# include <htlist.H>
34# include <tpl_dynDlist.H>
35# include <tpl_dynArray.H>
36# include <tpl_dynSetTree.H>
37# include <tpl_dynSetHash.H>
38# include <tpl_dynBinHeap.H>
39# include <tpl_dynArrayHeap.H>
40# include <tpl_graph.H>
41# include <tpl_sgraph.H>
42# include <tpl_agraph.H>
43# include <tpl_net.H>
44# include <tpl_netcost.H>
45
46using namespace std;
47using namespace Aleph;
48
49struct Foo
50{
51 int f1 = -1;
52 string f2 = "hello";
53 float f3 = 0;
54
55 Foo() {}
56
57 Foo(int __f1) : f1(__f1) {}
58
59 Foo(string __f2) : f2(__f2) {}
60
61 Foo(int __f1, const string & __f2) : f1(__f1), f2(__f2) {}
62
63 Foo(int __f1, const string & __f2, float __f3)
64 : f1(__f1), f2(__f2), f3(__f3) {}
65
66 friend ostream & operator << (ostream & s, const Foo & foo)
67 {
68 return s << "(" << foo.f1 << "," << foo.f2 << "," << foo.f3 << ")";
69 }
70};
71
72template <template <typename> class C>
73void test()
74{
75 int i = 7;
76 string str = "salut";
77 float f = 10e6;
78 C<Foo> c;
79 c.emplace(2);
80 c.emplace(3, "hola");
81 c.emplace(4, "adios", -1.0);
82 c.emplace(5, str);
83 c.emplace(6, str, f);
84 c.emplace(i, str, 2.5);
85
86 c.for_each([] (auto foo) { cout << foo; });
87 cout << endl;
88}
89
91{
92 int i = 7;
93 string str = "salut";
94 float f = 10e6;
95
96 {
98
99 auto p1 = g.emplace_node(2);
100 auto p2 = g.emplace_node(3, "hola");
101 auto p3 = g.emplace_node(4, "adios", -1.0);
102 auto p4 = g.emplace_node(5, str);
103 auto p5 = g.emplace_node(6, str, f);
104 auto p6 = g.emplace_node(i, str, 2.5);
105
106 g.emplace_arc(p1, p2, 0);
107 g.emplace_arc(p3, p4, i, str, f);
108 g.emplace_arc(p5, p6, 0, "soyuz");
109 }
110
111 cout << endl
112 << endl;
113
114 {
116 auto p1 = g.emplace_node(2);
117 auto p2 = g.emplace_node(3, "hola");
118 auto p3 = g.emplace_node(4, "adios", -1.0);
119 auto p4 = g.emplace_node(5, str);
120 auto p5 = g.emplace_node(6, str, f);
121 auto p6 = g.emplace_node(i, str, 2.5);
122
123 g.insert_arc(p1, p2, 0);
124 g.emplace_arc(p3, p4, 0, 0, i, str, f);
125 g.insert_arc(p5, p6, 0);
126 }
127
128 {
130 auto p1 = g.emplace_node(2);
131 auto p2 = g.emplace_node(3, "hola");
132 auto p3 = g.emplace_node(4, "adios", -1.0);
133 auto p4 = g.emplace_node(5, str);
134 auto p5 = g.emplace_node(6, str, f);
135 auto p6 = g.emplace_node(i, str, 2.5);
136
137 g.insert_arc(p1, p2, 10, 10);
138 g.emplace_arc(p3, p4, 0, 0, i, str, f);
139 g.insert_arc(p5, p6, 20, 20);
140 }
141}
142
143int main()
144{
148
149
150 test_graph();
151}
Arc * emplace_arc(Node *src, Node *tgt, Args &&... args)
Insert a new arc in the graph by constructing its associated data in-place with the given args.
Definition graph-dry.H:1300
Node * emplace_node(Args &&... args)
Insert a new node in the graph by constructing it in-place with the given args.
Definition graph-dry.H:1214
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
STL namespace.
Arc of a flow network implemented with adjacency lists.
Definition tpl_net.H:115
Arc type for maximum flow minimum cost networks.
Definition tpl_netcost.H:95
Capacitated flow network with costs associated to arcs.
Arc * emplace_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &__cost, Args &&... args)
Create and insert an arc with arc info using perfect forwarding.
virtual Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &__cost)
Create and insert an arc in a flow network with costs.
Flow network implemented with adjacency lists.
Definition tpl_net.H:261
Node * emplace_node(Args &&... args)
Construct a node in-place and insert it into the network.
Definition tpl_net.H:578
Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, const typename Arc::Arc_Type &arc_info=Arc_Type())
Insert a capacitated arc with an initial flow.
Definition tpl_net.H:607
Arc * emplace_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, Args &&... args)
Construct arc info in-place and insert the arc.
Definition tpl_net.H:626
Foo(int __f1, const string &__f2, float __f3)
friend ostream & operator<<(ostream &s, const Foo &foo)
float f3
Foo(string __f2)
int f1
Foo(int __f1)
string f2
Foo(int __f1, const string &__f2)
void test_graph()
void test()
int main()
Array-based graph implementation.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Generic graph and digraph implementations.
Network flow graph structures.
Maximum flow minimum cost network algorithms.
Simple graph implementation with adjacency lists.