Make bucket size match constant in Lox library for all functions

This commit is contained in:
onyinyang 2023-04-10 12:16:19 -04:00
parent b92cd242e7
commit 8f22a13074
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 11 additions and 17 deletions

View File

@ -91,11 +91,12 @@ impl LoxServerContext {
pub fn remove_extra_bridges(&self) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] { pub fn remove_extra_bridges(&self) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] {
let mut extra_bridges = self.extra_bridges.lock().unwrap(); let mut extra_bridges = self.extra_bridges.lock().unwrap();
[ let mut return_bridges = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
extra_bridges.remove(0), for i in 0..MAX_BRIDGES_PER_BUCKET{
extra_bridges.remove(1), return_bridges[i] = extra_bridges.remove(i);
extra_bridges.remove(2), }
]
return_bridges
} }

View File

@ -7,6 +7,7 @@ use hyper::{
service::{make_service_fn, service_fn}, service::{make_service_fn, service_fn},
Body, Method, Request, Response, Server, StatusCode, Body, Method, Request, Response, Server, StatusCode,
}; };
use lox::bridge_table::MAX_BRIDGES_PER_BUCKET;
use lox::bridge_table::{BridgeLine, BRIDGE_BYTES}; use lox::bridge_table::{BridgeLine, BRIDGE_BYTES};
use lox::{BridgeAuth, BridgeDb}; use lox::{BridgeAuth, BridgeDb};
@ -192,11 +193,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
Rdsys { resourcediff } => { Rdsys { resourcediff } => {
if let Some(new_resources) = resourcediff.new { if let Some(new_resources) = resourcediff.new {
let mut count = 0; let mut count = 0;
let mut bucket = [ let mut bucket= [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
for pt in new_resources { for pt in new_resources {
println!("A NEW RESOURCE: {:?}", pt); println!("A NEW RESOURCE: {:?}", pt);
for resource in pt.1 { for resource in pt.1 {
@ -225,7 +222,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
info: info_bytes, info: info_bytes,
}; };
println!("Now it's a bridgeline: {:?}", bridgeline); println!("Now it's a bridgeline: {:?}", bridgeline);
if count < 2 { if count < MAX_BRIDGES_PER_BUCKET-1 {
bucket[count] = bridgeline; bucket[count] = bridgeline;
count += 1; count += 1;
} else { } else {
@ -233,18 +230,14 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
// eventually also do some more fancy grouping of new resources, i.e., by type or region // eventually also do some more fancy grouping of new resources, i.e., by type or region
context.add_openinv_bucket(bucket); context.add_openinv_bucket(bucket);
count = 0; count = 0;
bucket = [ bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
} }
} }
} }
// Handle the extra buckets that were not allocated already // Handle the extra buckets that were not allocated already
if count != 0 { if count != 0 {
for val in 0..count { for val in 0..count {
if context.extra_bridges.lock().unwrap().len() < 2 { if context.extra_bridges.lock().unwrap().len() < (MAX_BRIDGES_PER_BUCKET-1) {
context.append_extra_bridges(bucket[val]); context.append_extra_bridges(bucket[val]);
} else { } else {
bucket = context.remove_extra_bridges(); bucket = context.remove_extra_bridges();