[UTILS] Fix and resolve remote references in standard defined domain
[oom/utils.git] / external-schema-repo-generator / generator / bin_packing.awk
1 # ============LICENSE_START=======================================================
2 # OOM
3 # ================================================================================
4 # Copyright (C) 2020-2021 Nokia. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
16
17 function first_fit(v, file) {
18     # find first bin that can accomodate the volume
19     for (i=1; i<=n; ++i) {
20         if (b[i] > v) {
21             b[i] -= v
22             bc[i]++
23             cmd="mkdir -p "tmpLocation"/"schema"-subdir-"i"/OpenAPI"
24             system(cmd)
25             cmd="mv "file" " tmpLocation"/"schema  "-subdir-" i "/OpenAPI"
26             system(cmd)
27             return
28         }
29     }
30     # no bin found, create new bin
31     if (i > n) {
32         b[++n] = c - v
33         bc[n]++
34         cmd="mkdir -p "tmpLocation"/"schema"-subdir-"n"/OpenAPI"
35         system(cmd)
36         cmd="mv "file" " tmpLocation"/"schema  "-subdir-"n"/OpenAPI"
37         system(cmd)
38     }
39     return
40 }
41 BEGIN{ if( (c+0) == 0) exit }
42 { first_fit($1,$2) }
43 END { print "REPORT:"
44     print "Created",n,"directories"
45     for(i=1;i<=n;++i) {
46             print "- "tmpLocation"/"schema"-subdir-"i,":", c-b[i],"bytes",bc[i],"files"
47     }
48 }