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] {
let mut extra_bridges = self.extra_bridges.lock().unwrap();
[
extra_bridges.remove(0),
extra_bridges.remove(1),
extra_bridges.remove(2),
]
let mut return_bridges = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
for i in 0..MAX_BRIDGES_PER_BUCKET{
return_bridges[i] = extra_bridges.remove(i);
}
return_bridges
}

View File

@ -7,6 +7,7 @@ use hyper::{
service::{make_service_fn, service_fn},
Body, Method, Request, Response, Server, StatusCode,
};
use lox::bridge_table::MAX_BRIDGES_PER_BUCKET;
use lox::bridge_table::{BridgeLine, BRIDGE_BYTES};
use lox::{BridgeAuth, BridgeDb};
@ -192,11 +193,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
Rdsys { resourcediff } => {
if let Some(new_resources) = resourcediff.new {
let mut count = 0;
let mut bucket = [
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
let mut bucket= [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
for pt in new_resources {
println!("A NEW RESOURCE: {:?}", pt);
for resource in pt.1 {
@ -225,7 +222,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
info: info_bytes,
};
println!("Now it's a bridgeline: {:?}", bridgeline);
if count < 2 {
if count < MAX_BRIDGES_PER_BUCKET-1 {
bucket[count] = bridgeline;
count += 1;
} 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
context.add_openinv_bucket(bucket);
count = 0;
bucket = [
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
}
}
}
// Handle the extra buckets that were not allocated already
if count != 0 {
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]);
} else {
bucket = context.remove_extra_bridges();