-
Notifications
You must be signed in to change notification settings - Fork 0
/
Libraries.sol
120 lines (88 loc) · 2.93 KB
/
Libraries.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//SPDX-License-Identifier:Unlicensed
pragma solidity ^0.8.0;
library Math {
function plus(uint x ,uint y )public pure returns (uint){
return x+y ;
}
function minus( uint x, uint y) public pure returns (uint) {
return x-y ;
}
function multi(uint x, uint y) public pure returns ( uint) {
return x*y;
}
function divide(uint x ,uint y)public pure returns(uint){
require(y!=0,"Tanimsiz deger");
return x/y;
}
function min(uint x, uint y) public pure returns(uint) {
if( x <= y){
return x;
}else {
return y;
}
}
function max(uint x, uint y) public pure returns(uint) {
if( x >= y){
return x;
}else {
return y;
}
}
}
library Search{
function indexOf(uint[] memory list,uint data )public pure returns (uint){
for (uint i=0; i<list.length; i++) {
if (list[i]==data) {
return i;
}
}
return list.length;
}
}
contract Library{
using Math for uint;
using Search for uint[];
function trialornek(uint[] memory x,uint y)public pure returns(uint){
return Search.indexOf(x,y);
//return x.indexOf(y); using Search for uint [] kullanıldığında bu kullanılır
}
function trial1(uint x,uint y) public pure returns(uint){
//return x.plus(y); ----> bunu using math for uint yazdığımız zaman kullanıyoruz
return Math.plus(x,y);
}
function trial2(uint x,uint y) public pure returns(uint) {
return Math.minus(x,y);
}
function trial3( uint x, uint y) public pure returns(uint) {
return Math.multi(x,y);
}
function trial4( uint x, uint y) public pure returns( uint) {
return Math.divide(x,y);
}
function trial5( uint x, uint y) public pure returns( uint) {
return Math.min(x,y);
}
function trial6( uint x, uint y) public pure returns( uint) {
return Math.max(x,y);
}
}
library Human{
struct Person{
uint age;
}
function birthday(Person storage _person)public{
_person.age+=1;
}
function showAge(Person storage _person) public view returns (uint){
return _person.age;
}
}
contract HumanContract{
mapping(uint =>Human.Person) public people;
function newYear()public{
Human.birthday(people[0]);
}
function getAge()public view returns(uint){
return Human.showAge(people[0]);
}
}