Class: Bayonetta::DATFile::HashMap
- Inherits:
-
LibBin::Structure
- Object
- LibBin::Structure
- Bayonetta::DATFile::HashMap
- Defined in:
- lib/bayonetta/dat.rb
Defined Under Namespace
Classes: Header
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize ⇒ HashMap
constructor
A new instance of HashMap.
- #set(hash_map) ⇒ Object
Constructor Details
Instance Method Details
#get ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bayonetta/dat.rb', line 42 def get { pre_hash_shift: @header.pre_hash_shift, hashes: file_indices.zip(hashes).sort { |(i1 ,h1), (i2, h2)| i1 <=> i2 }.collect { |i, h| h } } end |
#set(hash_map) ⇒ Object
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 |
# File 'lib/bayonetta/dat.rb', line 58 def set(hash_map) bit_shift = hash_map[:pre_hash_shift] hash_list = hash_map[:hashes] num_files = hash_list.size @header.pre_hash_shift = bit_shift buckets = Hash::new { |h, k| h[k] = [] } hash_list.each_with_index { |h, i| bucket_index = h >> @header.pre_hash_shift buckets[bucket_index].push [h, i] } @bucket_ranks = [] @hashes = [] @file_indices = [] bucket_rank = 0 num_buckets = (1 << (31 - header.pre_hash_shift)) num_buckets.times { |i| if buckets.has_key?(i) @bucket_ranks.push bucket_rank bucket_rank += buckets[i].size buckets[i].each { |h, ind| @hashes.push h @file_indices.push ind } else @bucket_ranks.push -1 end } @header.offset_bucket_ranks = 0x10 @header.offset_hashes = header.offset_bucket_ranks + num_buckets * 2 @header.offset_file_indices = header.offset_hashes + num_files * 4 self end |