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 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27# include <iostream>
28# include <htlist.H>
29# include <tpl_dynDlist.H>
30# include <tpl_dynArray.H>
31# include <tpl_dynSetTree.H>
32# include <tpl_dynSetHash.H>
33# include <tpl_dynBinHeap.H>
34# include <tpl_dynArrayHeap.H>
35# include <tpl_graph.H>
36# include <tpl_sgraph.H>
37# include <tpl_agraph.H>
38# include <tpl_net.H>
39# include <tpl_netcost.H>
40
41using namespace std;
42using namespace Aleph;
43
44struct Foo
45{
46 int f1 = -1;
47 string f2 = "hello";
48 float f3 = 0;
49
50 Foo() {}
51
52 Foo(int __f1) : f1(__f1) {}
53
54 Foo(string __f2) : f2(__f2) {}
55
56 Foo(int __f1, const string & __f2) : f1(__f1), f2(__f2) {}
57
58 Foo(int __f1, const string & __f2, float __f3)
59 : f1(__f1), f2(__f2), f3(__f3) {}
60
61 friend ostream & operator << (ostream & s, const Foo & foo)
62 {
63 return s << "(" << foo.f1 << "," << foo.f2 << "," << foo.f3 << ")";
64 }
65};
66
67template <template <typename> class C>
68void test()
69{
70 int i = 7;
71 string str = "salut";
72 float f = 10e6;
73 C<Foo> c;
74 c.emplace(2);
75 c.emplace(3, "hola");
76 c.emplace(4, "adios", -1.0);
77 c.emplace(5, str);
78 c.emplace(6, str, f);
79 c.emplace(i, str, 2.5);
80
81 c.for_each([] (auto foo) { cout << foo; });
82 cout << endl;
83}
84
86{
87 int i = 7;
88 string str = "salut";
89 float f = 10e6;
90
91 {
93
94 auto p1 = g.emplace_node(2);
95 auto p2 = g.emplace_node(3, "hola");
96 auto p3 = g.emplace_node(4, "adios", -1.0);
97 auto p4 = g.emplace_node(5, str);
98 auto p5 = g.emplace_node(6, str, f);
99 auto p6 = g.emplace_node(i, str, 2.5);
100
101 g.emplace_arc(p1, p2, 0);
102 g.emplace_arc(p3, p4, i, str, f);
103 g.emplace_arc(p5, p6, 0, "soyuz");
104 }
105
106 cout << endl
107 << endl;
108
109 {
111 auto p1 = g.emplace_node(2);
112 auto p2 = g.emplace_node(3, "hola");
113 auto p3 = g.emplace_node(4, "adios", -1.0);
114 auto p4 = g.emplace_node(5, str);
115 auto p5 = g.emplace_node(6, str, f);
116 auto p6 = g.emplace_node(i, str, 2.5);
117
118 g.insert_arc(p1, p2, 0);
119 g.emplace_arc(p3, p4, 0, 0, i, str, f);
120 g.insert_arc(p5, p6, 0);
121 }
122
123 {
125 auto p1 = g.emplace_node(2);
126 auto p2 = g.emplace_node(3, "hola");
127 auto p3 = g.emplace_node(4, "adios", -1.0);
128 auto p4 = g.emplace_node(5, str);
129 auto p5 = g.emplace_node(6, str, f);
130 auto p6 = g.emplace_node(i, str, 2.5);
131
132 g.insert_arc(p1, p2, 10, 10);
133 g.emplace_arc(p3, p4, 0, 0, i, str, f);
134 g.insert_arc(p5, p6, 20, 20);
135 }
136}
137
138int main()
139{
143
144
145 test_graph();
146}
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:1258
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:1172
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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:93
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.